diff --git a/changelog.txt b/changelog.txt index 3821ca2..9d68ae9 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,102 @@ +--------------------------------------------------------------------------------------------------- +Version: 0.7.4 +Date: 17.08.2019 + Changes: + - Added more mod remote commands + - Added tile overrides to disable certain tiles unless otherwise enabled. + +--------------------------------------------------------------------------------------------------- +Version: 0.7.3 +Date: 17.08.2019 + Changes: + - migration issues + +--------------------------------------------------------------------------------------------------- +Version: 0.7.2 +Date: 17.08.2019 + Changes: + - More bug fix + +--------------------------------------------------------------------------------------------------- +Version: 0.7.1 +Date: 17.08.2019 + Changes: + - Progress on mod compatability Alien Biomes + +--------------------------------------------------------------------------------------------------- +Version: 0.7.0 +Date: 17.08.2019 + Changes: + - Fixed gui not updating on autowarp settings changes + - Added a fix to make spawn area resources spawn further away from the platform as it gets bigger (this apparently did nothing) + + +--------------------------------------------------------------------------------------------------- +Version: 0.6.9 +Date: 17.08.2019 + Changes: + - Mod setting for %chance of landing on selected planet + - Added Warp Portal item + +--------------------------------------------------------------------------------------------------- +Version: 0.6.8 +Date: 17.08.2019 + Changes: + - Fixed a bug with the warp charge timer + - Fixed a bug with the planets gui dropdown + - Fixed missing ocean planet description + - Planets API tweaks + - Fixed player corpse between warps + +--------------------------------------------------------------------------------------------------- +Version: 0.6.7 +Date: 15.08.2019 + Changes: + - Added fix for dropped items being lost on warp + - More 0.6.5 typos + +--------------------------------------------------------------------------------------------------- +Version: 0.6.6 +Date: 15.08.2019 + Changes: + - Added missing multiplier for original map settings starting_area and water + - 0.6.5 typo + +--------------------------------------------------------------------------------------------------- +Version: 0.6.5 +Date: 15.08.2019 + Changes: + - Fixed a big with picking up warp heatpipes + - Fixed a bug with the early boiler room water setting not working when starting a new map with it enabled (migration for this is done too) + - Fixed a bug with modded ores not appearing on any planets + - Added checks to ensure resource specific planets are not spawned if a mod is added that removes base game resources. + - Fixed interactions with Factorissimo2 + - More progress on Alien Biomes compatability (trees and such should spawn now). It should only spawn nauvis-like planets currently. + +--------------------------------------------------------------------------------------------------- +Version: 0.6.4 +Date: 12.08.2019 + Changes: + - Fixed typos in 0.6.3 + + +--------------------------------------------------------------------------------------------------- +Version: 0.6.3 +Date: 12.08.2019 + Changes: + - Temporarily disabled loader mod detection + - Re-wrote the planet generator with improved mod compatability and improved api + - Tweaked a bunch of planet generation settings + - Added Uncharted planet + +--------------------------------------------------------------------------------------------------- +Version: 0.6.2 +Date: 12.08.2019 + Changes: + - Added mod compatability: Mods that introduce new/faster loaders will replace the existing platform loaders at logistics level 4. Exception: miniloaders + - Prep for mod compatible planet generator update + --------------------------------------------------------------------------------------------------- Version: 0.6.1 Date: 11.08.2019 diff --git a/control.lua b/control.lua index 984cda4..76e97b1 100644 --- a/control.lua +++ b/control.lua @@ -17,9 +17,16 @@ function table.HasValue(t,a) for k,v in pairs(t)do if(v==a)then return true end function table.GetValueIndex(t,a) for k,v in pairs(t)do if(v==a)then return k end end return false end function table.RemoveByValue(t,a) local i=table.GetValueIndex(t,a) if(i)then table.remove(t,i) end end function table.insertExclusive(t,a) if(not table.HasValue(t,a))then return table.insert(t,a) end return false end -function table.deepmerge(s,t) for k,v in pairs(t)do if(istable(v) and s[k] and istable(s[k]))then table.deepmerge(s[k],v) else s[k]=v end end end +function table.deepmerge(s,t) for k,v in pairs(t)do if(istable(v) and s[k] and istable(s[k]))then if(table_size(v)==0)then s[k]=s[k] or {} else table.deepmerge(s[k],v) end else s[k]=v end end end function table.merge(s,t) local x={} for k,v in pairs(s)do x[k]=v end for k,v in pairs(t)do x[k]=v end return x end +function table.GetMatchTable(t,n) local x={} + if(istable(n))then for k,v in pairs(t)do if(table.HasMatchValue(n,v))then table.insert(x,v) end end + else for i,v in pairs(t)do if(v:match(n))then table.insert(x,v) end end + end return x +end +function table.HasValueMatch(t,u) for k,v in pairs(t)do if(v:match(u))then return v end end end +function table.HasMatchValue(t,u) for k,v in pairs(t)do if(u:match(v))then return v end end end warptorio=warptorio or {} --warptorio.LogisticLoaderChestProvider="logistic-chest-active-provider" @@ -27,7 +34,7 @@ warptorio=warptorio or {} require("control_planets") require("control_research") -require("control_nauvis") --function warptorio.OverrideNauvis() end-- +--require("control_nauvis") --function warptorio.OverrideNauvis() end-- warptorio.railCorn={nw={x=-35,y=-35},ne={x=34,y=-35},sw={x=-35,y=34},se={x=34,y=34}} @@ -104,9 +111,17 @@ function TRAIL:BalanceChests() local inv={} for k,v in pairs(self.chests)do inv[ local ci for a,b in pairs(ct)do local g=b ci=#inv for k,v in pairs(inv)do local gci=math.ceil(g/ci) if(gci>0)then local w=v.insert{name=a,count=math.ceil(g/ci)} ci=ci-1 g=g-w end end end end +function warptorio.GetFastestLoader() if(warptorio.FastestLoader)then return warptorio.FastestLoader end if(true)then return "express-loader" end + local ld={} + local topspeed=game.entity_prototypes["express-loader"].belt_speed local top="express-loader" + for k,v in pairs(game.entity_prototypes)do if(v.type=="loader")then table.insert(ld,v) end end + for k,v in pairs(ld)do if(not v.name:match("warptorio") and not v.name:match("mini") and v.belt_speed>=topspeed)then topspeed=v.belt_speed top=v.name end end + warptorio.FastestLoader=top return top +end + function warptorio.GetLogisticsChestBelt(dir) local lv=gwarptorio.Research["factory-logistics"] or 0 if(lv<=1)then return "wooden-chest","loader" elseif(lv==2)then return "iron-chest","fast-loader" elseif(lv==3)then return "steel-chest","express-loader" - elseif(lv>=4)then return (dir=="output" and gwarptorio.LogisticLoaderChestProvider or gwarptorio.LogisticLoaderChestRequester),"express-loader" end + elseif(lv>=4)then return (dir=="output" and gwarptorio.LogisticLoaderChestProvider or gwarptorio.LogisticLoaderChestRequester),warptorio.GetFastestLoader() end end function TRAIL:DoMakes(udir) local chest,belt=warptorio.GetLogisticsChestBelt(self.dir) if(not udir)then self:MakeRails() end self:MakeChests(chest) self:MakeLoaders(belt) end @@ -288,7 +303,7 @@ function TELL:SpawnLogistics() if(not self.logs)then self.logs={} end if(lv==1)then chest,belt="wooden-chest","loader" elseif(lv==2)then chest,belt="iron-chest","fast-loader" elseif(lv==3)then chest,belt="steel-chest","express-loader" - elseif(lv>=4)then chest,belt="logistic-chest-buffer","express-loader" end + elseif(lv>=4)then chest,belt="logistic-chest-buffer",warptorio.GetFastestLoader() end local dl=0 if(self.name=="b1" or self.name=="b2")then dl=gwarptorio.Research["dualloader"] or 0 else dl=gwarptorio.Research["triloader"] or 0 end @@ -300,7 +315,7 @@ function TELL:SpawnLogistics() if(not self.logs)then self.logs={} end if(b and b.valid)then if(self.name=="offworld")then -- check for collisions if(b.surface.name == f.name)then local bp=b.position local bb={bp.x-5,bp.y-1} local bbox={bb,{bb[1]+9,bb[2]+2}} - if(f.count_entities_filtered{area=bbox,collision_mask={"object-layer"}} > 1)then game.print("Unable to place teleporter logistics, something is in the way!") + if(f.count_entities_filtered{area=bbox,collision_mask={"object-layer"}} > 1)then if(not warptorio.IsWarping)then game.print("Unable to place teleporter logistics, something is in the way!") end else self:SpawnLogisticsPoint("b",self.PointB,chest,belt,pipe,dl,lv) end else @@ -361,7 +376,7 @@ function tpcls.b1(upgr,logs) local e=x:SpawnPointB(makeB,fb,{x=-1,y=-7}) e.minable=false e.destructible=false end - --x:ConnectCircuit() + x:ConnectCircuit() if(lgv and not upgr)then x:SpawnLogistics() end warptorio.playsound("warp_in",f.name) @@ -382,7 +397,7 @@ function tpcls.b2(upgr,logs) if(x:ValidPointB())then if((logs or x.PointB.surface~=fb))then x:DestroyPointB() x:DestroyLogisticsB() elseif(x.PointB.name~=makeB)then x:DestroyPointB() bdes=true end end local vx = -2-(lgv and 2 or 0)-lgx local vw = 3+(lgv and 4 or 0)+lgx*2 - if(not x:ValidPointA())then if(not ades)then warptorio.cleanbbox(f,vx,4,vw,3) end local e=x:SpawnPointA(makeA,f,{x=-1,y=5}) e.minable=false end + if(not x:ValidPointA())then if(not ades)then warptorio.cleanbbox(f,vx,4,vw,3) end local e=x:SpawnPointA(makeA,f,{x=-1,y=5}) e.minable=false e.destructible=false end if(not x:ValidPointB())then if(not bdes)then warptorio.cleanbbox(fb,vx,4,vw,3) end local e=x:SpawnPointB(makeB,fb,{x=-1,y=5}) e.minable=false e.destructible=false end if(lgv and not upgr)then x:SpawnLogistics() end @@ -407,7 +422,7 @@ function warptorio.SpawnTurretTeleporter(c,xp,yp,upgr,logs) local lgx=gwarptorio.Research["triloader"] or 0 local vx = -1-(lgv and 2 or 0)-lgx local vw = 3+(lgv and 4 or 0)+lgx*2 - if(not x:ValidPointA())then if(not (upgr) and not ades)then warptorio.cleanbbox(f,xp+vx,yp-1,vw,3) end local e=x:SpawnPointA(makeA,f,{x=xp,y=yp}) e.minable=false end + if(not x:ValidPointA())then if(not (upgr) and not ades)then warptorio.cleanbbox(f,xp+vx,yp-1,vw,3) end local e=x:SpawnPointA(makeA,f,{x=xp,y=yp}) e.minable=false e.destructible=false end if(not x:ValidPointB())then if(not (upgr) and not bdes)then warptorio.cleanbbox(fb,xp+vx,yp-1,vw,3) end local e=x:SpawnPointB(makeB,fb,{x=xp,y=yp}) e.minable=false e.destructible=false end if(lgv and not upgr)then x:SpawnLogistics() end @@ -603,6 +618,8 @@ function warptorio.BuildB1() local m=gwarptorio.Floors.b1 local f=m:GetSurface() warptorio.playsound("warp_in",f.name) end + + function warptorio.BuildB2() local m=gwarptorio.Floors.b2 local f,z=m:GetSurface(),m.z local lvc={} for k,v in pairs({"nw","ne","sw","se"})do lvc[k]=gwarptorio.Research["turret-"..v] or -1 end @@ -657,7 +674,7 @@ function warptorio.TickTeleporters(e) for k,v in pairs(gwarptorio.Teleporters)do local bp=o.position local dist=math.sqrt((x.x+bp.x)^2+(x.y+bp.y)^2) local jc=(inv*2000)*(1+dist/200) if(e.energy0)then zx=zx+v.rng end end --for i=1,(v.rng or 1) do table.insert(zp,k) end end end + for k,v in pairs(warptorio.Planets)do if(v.zone<=z and v.rng>0 and warptorio.PlanetCanSpawn(v))then zx=zx+v.rng table.insert(zp,k) end end --for i=1,(v.rng or 1) do table.insert(zp,k) end end end if(zx<=0)then return warptorio.Planets["normal"] end local rng=math.random(1,zx) local zy=0 - for k,v in pairs(warptorio.Planets)do if(v.zone<=z and v.rng>0)then zy=zy+v.rng if(rng<=zy)then return v end end end + for _,k in pairs(zp)do local v=warptorio.Planets[k] if(v.zone<=z and v.rng>0)then zy=zy+v.rng if(rng<=zy)then return v end end end return warptorio.Planets["normal"] end @@ -1245,31 +1318,41 @@ function warptorio.DoNextPlanet() local w=warptorio.RandomPlanet(gwarptorio.warpzone+1) return w end - -function warptorio.CheckPlanetControls(t) -- mod compatability -_- - local pt=game.autoplace_control_prototypes - if(warptorio.alienBiomes)then warptorio.DoAlienBiomesTiles(t) end - for k,v in pairs(t.autoplace_controls)do if(not pt[k])then t.autoplace_controls[k]=nil end end +function warptorio.PlanetCanSpawn(p) + if(p.required_controls)then for k,v in pairs(p.required_controls)do if(not game.autoplace_control_prototypes[v])then return false end end end + return true end + function warptorio.BuildNewPlanet(vplanet) local w if(vplanet)then w=warptorio.Planets[vplanet] end local lvl=gwarptorio.Research["reactor"] or 0 + local sizelv=(gwarptorio.Research["platform-size"] or 0) + --warptorio.TweakResourcePlacements(9999) --1+(sizelv*0.33)) + if(lvl>=8 and gwarptorio.planet_target and not w)then local wx=gwarptorio.planet_target if(wx=="home")then if(gwarptorio.Floors.main:GetSurface().name~=gwarptorio.Floors.home:GetSurface().name and math.random(1,10)<=3)then game.print("-Successful Warp-") game.print(gwarptorio.Floors.home.world.name .. ". Home sweet home.") return gwarptorio.Floors.home:GetSurface(),gwarptorio.Floors.home.world end - elseif(math.random(1,10)<=3)then - w=warptorio.Planets[wx] if(w)then game.print("-Successful Warp-") end + elseif(math.random(1,100)<=settings.global["warptorio_warpchance"].value)then + w=warptorio.Planets[wx] if(not warptorio.PlanetCanSpawn(w))then w=nil elseif(w)then game.print("-Successful Warp-") end end end if(not w)then w=warptorio.RandomPlanet() end if(gwarptorio.charting or not w.desc)then game.print(w.name) end if(w.desc)then game.print(w.desc) end + + local g=warptorio.GeneratePlanetSettings(w,gwarptorio.charting) + local f=warptorio.GeneratePlanetSurface(w,g,gwarptorio.charting) + + return f,w,g +end + +--[[ old buildplanet code --game.print("Generating Planet: " .. w.name) local orig=(game.surfaces["nauvis"].map_gen_settings) @@ -1300,6 +1383,8 @@ function warptorio.BuildNewPlanet(vplanet) local w return f,w end +]] + function warptorio.IsAutowarpEnabled() return gwarptorio.autowarp_disable~=true and (not gwarptorio.warp_reactor or not gwarptorio.warp_reactor.valid or gwarptorio.autowarp_always) end @@ -1320,6 +1405,7 @@ function warptorio.IsElectricPole(e) return (e.name:match("electric-pole") or e. local badEnts={"highlight-box"} function warptorio.Warpout(vplanet) + warptorio.IsWarping=true gwarptorio.warp_charge=0 gwarptorio.warp_charging=0 gwarptorio.warpzone = gwarptorio.warpzone+1 warptorio.updatelabel("warptorio_warpzone"," Warp number : " .. gwarptorio.warpzone) warptorio.updatelabel("warptorio_dowarp","Warp !") @@ -1355,7 +1441,7 @@ function warptorio.Warpout(vplanet) end -- Designate next planet and make new surface - local f,w=warptorio.BuildNewPlanet(vplanet) gwarptorio.planet=w + local f,w=warptorio.BuildNewPlanet(vplanet) -- Add planet warp multiplier if(w.warp_multiply)then gwarptorio.warp_charge_time=gwarptorio.warp_charge_time*w.warp_multiply gwarptorio.warp_time_left=gwarptorio.warp_time_left*w.warp_multiply end @@ -1370,13 +1456,21 @@ function warptorio.Warpout(vplanet) -- Clean and prepare old surface local tp=gwarptorio.Teleporters.offworld if(tp and tp:ValidPointB())then tp:DestroyPointB() tp:DestroyLogisticsB() end -- packup old teleporter gate - local vfFactorissimo=c.find_entities_filtered{name={"factory-1","factory-2","factory-3"}} - for k,v in pairs(vfFactorissimo)do script.raise_event(defines.events.on_marked_for_deconstruction,{entity=v}) end + --local vfFactorissimo=c.find_entities_filtered{name={"factory-1","factory-2","factory-3"}} + --for k,v in pairs(vfFactorissimo)do script.raise_event(defines.events.on_marked_for_deconstruction,{entity=v}) end + + if(gwarptorio.warpevent_name)then script.raise_event(gwarptorio.warpevent_name,{newplanet=f,newworld=w,oldplanet=c,oldworld=gwarptorio.planet}) end + if(gwarptorio.planet)then + local pnt=gwarptorio.planet + if(pnt.warpout)then pnt.onwarpout(f,w,c,pnt) end + if(pnt.warpout_call)then remote.call(pnt.warpout_call[1],pnt.warpout_call[2],f,w,c,pnt) end + end + gwarptorio.planet=w -- find entities and players to copy/transfer to new surface local tpply={} local cx=warptorio.corn local etbl={} - for k,v in pairs(c.find_entities_filtered{type="character",invert=true,area=m.area})do if(v.last_user or v.force.name=="player" or v.force.name=="enemy")then + for k,v in pairs(c.find_entities_filtered{type="character",invert=true,area=m.area})do if(v.type=="item-entity" or v.type=="character-corpse" or v.last_user or v.force.name=="player" or v.force.name=="enemy")then table.insert(etbl,v) end end @@ -1402,8 +1496,8 @@ function warptorio.Warpout(vplanet) -- do the cloning - --c.clone_entities{entities=etbl,destination_offset={0,0},destination_surface=f} --,destination_force=game.forces.player} - local clones={} for k,v in pairs(etbl)do if(v.valid)then table.insert(clones,v.clone{position=v.position,surface=f,force=v.force}) end end + c.clone_entities{entities=etbl,destination_offset={0,0},destination_surface=f} --,destination_force=game.forces.player} + --local clones={} for k,v in pairs(etbl)do if(v.valid)then table.insert(clones,v.clone{position=v.position,surface=f,force=v.force}) end end -- do the player teleport for k,v in pairs(tpply)do v[1].teleport(f.find_non_colliding_position("character",{v[2][1],v[2][2]},0,1,1),f) end @@ -1418,7 +1512,7 @@ function warptorio.Warpout(vplanet) --// cleanup past entities for k,v in pairs(etbl)do v.destroy{raise_destroy=true} end - for k,v in pairs(vfFactorissimo)do if(v.valid)then v.cancel_deconstruction(game.forces.player) end end + --for k,v in pairs(vfFactorissimo)do if(v.valid)then v.cancel_deconstruction(game.forces.player) end end --// radar -- game.forces.player.chart(f,{lefttop={x=-256,y=-256},rightbottom={x=256,y=256}}) @@ -1447,6 +1541,11 @@ function warptorio.Warpout(vplanet) warptorio.CheckReactor() + if(gwarptorio.warpevent_post_name)then script.raise_event(gwarptorio.warpevent_post_name,{newplanet=f,newworld=w}) end + if(w.postwarpout)then pnt.postwarpout(f,w) end + if(w.postwarpout_call)then remote.call(pnt.postwarpout_call[1],pnt.postwarpout_call[2],f,w) end + + warptorio.IsWarping=false end --[[c.clone_area{source_area=bbox,destination_area=bbox,destination_surface=f,destination_force=game.forces.player,expand_map=false,clone_tiles=true, clone_entities=true,clone_decoratives=false,clear_destination=true}]] @@ -1567,14 +1666,15 @@ function warptorio.MakeCarebearChest() end end +warptorio.Loaded=false function warptorio.Initialize() if(not global.warptorio)then global.warptorio={} gwarptorio=global.warptorio else gwarptorio=global.warptorio return end warptorio.Migrate() if(settings.global["warptorio_carebear"].value)then warptorio.MakeCarebearChest() end - if(settings.global["warptorio_water"].value)then game.forces.player.technologies["warptorio-boiler-water-1"].researched=true end + if(settings.global["warptorio_water"].value)then game.forces.player.technologies["warptorio-boiler-water-1"].researched=true gwarptorio.waterboiler=1 end for n,v in pairs(game.active_mods)do if(n=="alien-biomes")then warptorio.alienBiomes=true end end - warptorio.OverrideNauvis(true) + --warptorio.OverrideNauvis(true) end script.on_init(warptorio.Initialize) @@ -1589,8 +1689,8 @@ end script.on_load(warptorio.OnLoad) function warptorio.OnModSettingChanged(ev) local p=ev.player_index local s=ev.setting local st=ev.setting_type if(s=="warptorio_loaderchest_provider")then gwarptorio.LogisticLoaderChestProvider=settings.global[s].value elseif(s=="warptorio_loaderchest_requester")then gwarptorio.LogisticLoaderChestRequester=settings.global[s].value - elseif(s=="warptorio_autowarp_disable")then gwarptorio.autowarp_disable=settings.global[s].value - elseif(s=="warptorio_autowarp_always")then gwarptorio.autowarp_always=settings.global[s].value + elseif(s=="warptorio_autowarp_disable")then gwarptorio.autowarp_disable=settings.global[s].value for k,v in pairs(game.players)do warptorio.BuildGui(v) end + elseif(s=="warptorio_autowarp_always")then gwarptorio.autowarp_always=settings.global[s].value for k,v in pairs(game.players)do warptorio.BuildGui(v) end elseif(s=="warptorio_water")then if(settings.global[s].value)then game.forces.player.technologies["warptorio-boiler-water-1"].researched=true end elseif(s=="warptorio_carebear")then if(settings.global[s].value)then if(not isvalid(gwarptorio.warp_reactor) and not gwarptorio.carebear)then warptorio.MakeCarebearChest() end end elseif(s=="warptorio_loader_top")then for k,v in pairs(gwarptorio.Teleporters)do if(v.top)then v:UpgradeLogistics() end end @@ -1602,10 +1702,17 @@ function warptorio.OnConfigChanged(ev) warptorio.OnLoad() warptorio.Migrate() for n,v in pairs(game.active_mods)do if(n=="alien-biomes")then warptorio.alienBiomes=true end end - warptorio.OverrideNauvis() + + local fb=warptorio.GetFastestLoader() + if(gwarptorio.fastest_loader ~= fb)then + for k,v in pairs(gwarptorio.Teleporters)do v:UpgradeLogistics() end for k,v in pairs(gwarptorio.Rails)do v:DoMakes(true) end + gwarptorio.fastest_loader=fb + end + + --warptorio.OverrideNauvis() end script.on_configuration_changed(warptorio.OnConfigChanged) -function warptorio.Migrate() +function warptorio.Migrate() if(warptorio.Loaded)then return end gwarptorio.warpzone=gwarptorio.warpzone or 0 gwarptorio.time_spent_start_tick = gwarptorio.time_spent_start_tick or game.tick gwarptorio.time_passed = gwarptorio.time_passed or 0 @@ -1652,6 +1759,7 @@ function warptorio.Migrate() gwarptorio.LogisticLoaderChestProvider=settings.global['warptorio_loaderchest_provider'].value gwarptorio.LogisticLoaderChestRequester=settings.global['warptorio_loaderchest_requester'].value + warptorio.Loaded=true end @@ -1728,66 +1836,51 @@ function warptorio.cheat() for i,p in pairs(game.players)do for k,v in pairs(loo function warptorio.cmdwarp(v) warptorio.Warpout(v) end function warptorio.cmdresetplatform() warptorio.BuildPlatform() warptorio.BuildB1() warptorio.BuildB2() for k,v in pairs(gwarptorio.Teleporters)do v:Warpin() end end -function warptorio.cmdaddplanet(t) - local planet_table=t.planet_table - local fgen_event=t.fgen_event - local spawn_event=t.spawn_event - local suppress_errors=t.suppress_errors +function warptorio.cmdgetresources() return warptorio.GetAllResources() end +function warptorio.cmdgetglobal(k) return global.warptorio[k] end +function warptorio.cmdgetplanets() return warptorio.Planets end +function warptorio.cmdreveal(n) n=n or 10 local f=gwarptorio.Floors.main:GetSurface() game.forces.player.chart(f,{lefttop={x=-64-128*n,y=-64-128*n},rightbottom={x=64+128*n,y=64+128*n}}) end +function warptorio.cmdgetplanet(n) return warptorio.Planets[n] end +function warptorio.cmdgenerateplanet(n) return warptorio.GeneratePlanetSettings(warptorio.Planets[n],false) end - if(not planet_table.zone)then if(suppress_errors)then return false end error("Warptorio Error: 3rd party mod attempting to add planet without a zone") return false end - if(not planet_table.rng)then if(suppress_errors)then return false end error("Warptorio Error: 3rd party mod attempting to add planet without probability") return false end - if(not planet_table.name)then if(suppress_errors)then return false end error("Warptorio Error: 3rd party mod attempting to add planet without a name") return false end - if(warptorio.Planets[planet_table.name])then if(suppress_errors)then return false end error("Warptorio Error: 3rd party mod attempting to add a planet that already exists") return false end +function warptorio.cmdRegisterPlanet(t) warptorio.RegisterPlanet(t) end +function warptorio.cmdcurrentsurface() return gwarptorio.Floors.main:GetSurface() end +function warptorio.cmdhomesurface() return gwarptorio.Floors.home:GetSurface() end +function warptorio.cmdfactorysurface() return gwarptorio.Floors.b1:GetSurface() end +function warptorio.cmdboilersurface() return gwarptorio.Floors.b2:GetSurface() end - warptorio.Planets[planet_table.key] = table.deepcopy(planet_table) - warptorio.Planets[planet_table.key].fgen_event=fgen_event - warptorio.Planets[planet_table.key].spawn_event=spawn_event +function warptorio.cmdgetwarpevent() if(not gwarptorio.warpevent_name)then gwarptorio.warpevent_name = script.generate_event_name() end return gwarptorio.warpevent_name end +function warptorio.cmdgetpostwarpevent() if(not gwarptorio.warpevent_post_name)then gwarptorio.warpevent_post_name = script.generate_event_name() end return gwarptorio.warpevent_post_name end - return true -end +function warptorio.cmdtiledefault(n,b) warptorio.TileDefault(n,b) end -function warptorio.cmdupdateplanet(planet_name, planet_table,suppress_errors) - if(not planet_name)then if(suppress_errors)then return false end error("Warptorio Error: 3rd party mod attempting to update a planet without a name") return false end - if(not planet_table)then if(suppress_errors)then return false end error("Warptorio Error: 3rd party mod attempting to update a planet without a table") return false end - if(not warptorio.Planets[planet_name])then if(suppress_errors)then return false end error("Warptorio Error: 3rd party mod attempting to update a non-existant planet") return false end +remote.add_interface("warptorio",{ - local p=warptorio.Planets[planet_name] - warptorio.Planets[planet_name]=table.merge(p,planet_table) - return true -end -function warptorio.cmdgetcontrolmeta() return warptorio.PlanetControlMeta end -- see control_planets.lua + warp=warptorio.cmdwarp, -- force warp to a specific planet -function warptorio.cmdgetresources() - return warptorio.GetAllResources() -end -function warptorio.cmdgetglobal(k) - return global.warptorio[k] -end -function warptorio.cmdgetplanets() local t={} for k,v in pairs(warptorio.Planets)do table.insert(t,k) end return t end + tiledefault=warptorio.cmdtiledefault, -- add a tileset to not spawn by default in nauvis map_gen_settings using probability expressions, ex. see official planets pack -function warptorio.cmdreveal() - local n=10 - local f=gwarptorio.Floors.main:GetSurface() - game.forces.player.chart(f,{lefttop={x=-64-128*n,y=-64-128*n},rightbottom={x=64+128*n,y=64+128*n}}) -end + getplanets=warptorio.cmdgetplanets, -- get a copy of the current warptorio planets table + getplanet=warptorio.cmdgetplanet, -- get a copy of a specific planet -remote.add_interface("warptorio",{ - cheat=warptorio.cheat, - reveal=warptorio.cmdreveal, - warp=warptorio.cmdwarp, - resetplatform=warptorio.cmdresetplatform, - addplanet=warptorio.cmdaddplanet, - updateplanet=warptorio.cmdupdateplanet, - getplanets=warptorio.cmdgetplanets, - getcontrolmeta=warptorio.cmdgetcontrolmeta, - getresources=warptorio.cmdgetresources, - getglobal=warptorio.cmdgetglobal, -}) + getresources=warptorio.cmdgetresources, -- get a copy of the warptorio auto-detected resources "all resources", useful with mods + getglobal=warptorio.cmdgetglobal, -- get a variable from the global table + registerplanet=warptorio.cmdRegisterPlanet, -- register a new planet + currentplanet=warptorio.cmdcurrentsurface, -- get the current planet surface + homeplanet=warptorio.cmdhomesurface, -- get the homeworld surface + factorysurface=warptorio.cmdfactorysurface, -- get the factory surface + boilersurface=warptorio.cmdboilersurface, -- get the boiler surface + warpevent=warptorio.cmdgetwarpevent, -- get the named event for on warpout + postwarpevent=warptorio.cmdgetpostwarpevent, -- get the named event for post warpout ---remote.call("warptorio","cheat") ---remote.call("warptorio","resetplatform") ---remote.call("warptorio","warp") + cheat=warptorio.cheat, -- give free items cheat command for debugging purposes + reveal=warptorio.cmdreveal, -- map reveal cheat command for debugging purposes + generateplanet=warptorio.cmdgenerateplanet, -- generate a planet table for debugging purposes + resetplatform=warptorio.cmdresetplatform, -- Reconstruct the platforms for debugging purposes + + +}) function warptorio.OnChunkGenerated(ev) local a=ev.area local f=ev.surface @@ -1813,4 +1906,5 @@ function warptorio.OnChunkGenerated(ev) local a=ev.area local f=ev.surface --game.print("Insert Random Item: " .. tostring(k) .. " c: " .. cx .. " u: " .. tostring(u) .. " dv: " .. dv .. " fc: " .. fc) inv.insert{name=k,count=cx} end + end script.on_event(defines.events.on_chunk_generated,warptorio.OnChunkGenerated) diff --git a/control_planets.lua b/control_planets.lua index 62c6d02..bd1551d 100644 --- a/control_planets.lua +++ b/control_planets.lua @@ -1,291 +1,610 @@ --- -------- --- Warptorio Planets Module - -local function istable(x) return type(x)=="table" end -local function printx(m) for k,v in pairs(game.players)do v.print(m) end end -local function isvalid(v) return (v and v.valid) end -local function new(x,a,b,c,d,e,f,g) local t,v=setmetatable({},x),rawget(x,"__init") if(v)then v(t,a,b,c,d,e,f,g) end return t end - - -local planet={} warptorio.Planets=planet - -local resourceTypes={"coal","crude-oil","copper-ore","iron-ore","stone","uranium-ore"} -warptorio.OreTypes=resourceTypes ---["iron-ore"]={size=0},["copper-ore"]={size=0},["coal"]={size=0},["crude-oil"]={size=0},["uranium-ore"}={size=0},["stone"]={size=0} - -local czMeta={} warptorio.PlanetControlMeta=czMeta -function czMeta.__init(t,f,z,r) t.size=z or 1 t.frequency=f or 1 t.richness=r or 1 return t end -function czMeta.__mul(a,b) local t=setmetatable({},czMeta) if(istable(b))then for k,v in pairs(a)do t[k]=v*(b[k] or 1) end else for k,v in pairs(a)do t[k]=v*b end end return t end -function czMeta.__call(f,z,r) return new(czMeta,f,z,r) end -local function czControl(f,z,r) return {frequency=f or 1,size=z or 1,richness=r or 1} end - -local czRes=setmetatable({size=0.25,frequency=0.23,richness=0.22},czMeta) -local czCoal=setmetatable({size=0.275,frequency=0.3,richness=0.23},czMeta) -local czIron=setmetatable({size=0.25,frequency=0.25,richness=0.23},czMeta) -local czCopper=setmetatable({size=0.23,frequency=0.23,richness=0.21},czMeta) -local czUranium=setmetatable({size=0.25,frequency=0.25,richness=0.21},czMeta) -- this metatable is mostly used - --- "trees","grass","dirt","sand","desert" autoplace-control-names - -local function getrng(v) return settings.startup["warptorio_planet_"..v].value end - -local decal={} -decal.rocks={"rock-tiny","rock-small","rock-medium","rock-big","rock-huge"} -decal.sandrocks={"sand-rock-tiny","sand-rock-small","sand-rock-medium","sand-rock-big","sand-rock-huge"} -decal.sanddune={"sand-dune-decal","sand-decal","sand-rock"} -decal.bush={"white-desert-bush","green-bush-mini","desert-bush",} -decal.pita={"green-pita","green-pita-mini","red-asterisk"} -decal.mud={"dark-mud-decal"} -decal.garballo={"garballo","garballo-mini-dry"} -decal.puberty={"puberty-decal"} -decal.ship={"big-ship-wreck-1","small-ship-wreck-grass","medium-ship-wreck-grass","big-ship-wreck-grass","small-ship-wreck","medium-ship-wreck","big-ship-wreck"} - --- -------- --- Regular Planets - -planet.normal={ zone=0, rng=getrng("normal"), name="A Normal Planet", desc="This world reminds you of home."} -- default - -planet.average={ zone=2, rng=getrng("average"), name="An Average Planet", desc="The usual critters and riches surrounds you, but you feel like something is missing.", -- remove 1-2 resources - orig_mul=true, - gen={autoplace_controls={}}, - fgen=function(t,b,o) - local z,x=table.deepcopy(resourceTypes),{} for i=1,math.random(1,2),1 do local u=math.random(1,#z) x[i]=z[u] table.remove(z,u) end - for k,v in pairs(x)do t.autoplace_controls[v]=new(czMeta,0,0,0) end --{size=0} end - if(b)then local s=x[1] if(x[2])then s=s .. " and " .. x[2] .. " do" else s=s.. " does" end s=s.." not spawn on this planet" game.print(s) end - end, - spawn=function(f,b) +local gwarptorio=setmetatable({},{__index=function(t,k) return global.warptorio[k] end,__newindex=function(t,k,v) global.warptorio[k]=v end}) +local function PlanetRNG(name) return settings.startup["warptorio_planet_"..name].value end +local function ErrorNoHalt(s) game.print(s) end +warptorio=warptorio or {} - end, +--[[ Nauvis Whitelist ]]-- + +local nauvis={} warptorio.nauvis=nauvis +nauvis.autoplace={"trees","enemy-base"} -- game.autoplace_control_prototypes +nauvis.resource={"iron-ore","copper-ore","stone","coal","uranium-ore","crude-oil"} -- these are also autoplace + +nauvis.tile={ -- game.tile_prototypes with autoplace +"concrete","stone-path","tutorial-grid","refined-concrete","refined-hazard-concrete-left","refined-hazard-concrete-right","hazard-concrete-left","hazard-concrete-right", +"grass-1","grass-2","grass-3","grass-4","dirt-1","dirt-2","dirt-3","dirt-4","dirt-5","dirt-6","dirt-7","dry-dirt","sand-1","sand-2","sand-3", +"red-desert-0","red-desert-1","red-desert-2","red-desert-3", +"lab-dark-1","lab-dark-2","lab-white","landfill","out-of-map", +"water","deepwater", } -planet.dwarf={ zone=12, rng=getrng("dwarf"), name="A Dwarf Planet", desc="You are like a giant to the creatures of this planet. .. And to its natural resources.", -- half resources - orig_mul=true, - gen={ - autoplace_controls={["uranium-ore"]=czUranium*2,["enemy-base"]=setmetatable({frequency=0.5,size=0.5,richness=1},czMeta), - ["iron-ore"]=czIron*2,["copper-ore"]=czCopper*2,["coal"]=czCoal*2,["crude-oil"]=czRes*2,["stone"]=czRes*2, - } - }, +nauvis.noise={ -- game.noise_layer_prototypes, i think. todo: double check +"aux","brown-fluff","coal","copper-ore","crude-oil","dirt-1","dirt-2","dirt-3","dirt-4","dirt-5","dirt-6","dirt-7","dry-dirt", +"elevation","elevation-persistence","enemy-base","fluff","garballo", +"grass-1","grass-2","grass-3","grass-4","grass1","grass2","green-fluff","iron-ore","moisture","pita","pita-mini", +"red-desert-0","red-desert-1","red-desert-2","red-desert-3","red-desert-decal","rocks", +"sand-1","sand-2","sand-3","sand-decal","sand-dune-decal","starting-area","stone","temperature", +"trees","trees-1","trees-10","trees-11","trees-12","trees-13","trees-14","trees-15","trees-2","trees-3","trees-4","trees-5","trees-6","trees-7","trees-8","trees-9", +"uranium-ore", } +nauvis.decor={ -- game.decorative_prototypes with autoplace +"brown-hairy-grass","green-hairy-grass","brown-carpet-grass", +"green-carpet-grass","green-small-grass","green-asterisk", +"brown-asterisk-mini","green-asterisk-mini","brown-asterisk", +"red-asterisk","dark-mud-decal","light-mud-decal","puberty-decal", +"red-desert-decal","sand-decal","sand-dune-decal","green-pita", +"red-pita","green-croton","red-croton","green-pita-mini","brown-fluff", +"brown-fluff-dry","green-desert-bush","red-desert-bush","white-desert-bush", +"garballo-mini-dry","garballo","green-bush-mini","lichen","rock-medium", +"rock-small","rock-tiny","big-ship-wreck-grass","sand-rock-medium","sand-rock-small","small-ship-wreck-grass" --- -------- --- Other Planets +} -planet.jungle={ zone=27, rng=getrng("jungle"), name="A Jungle Planet", desc="These trees might be enough to conceal your location from the natives. .. At least for a while.", - orig_mul=true, - gen={autoplace_controls={["trees"]=setmetatable({frequency=2.5,size=2.5,richness=1.5},czMeta)}}, - spawn=function(f) f.daytime=math.random(0,1) end +nauvis.entities={ +"fish","tree-01","tree-02","tree-03","tree-04","tree-05","tree-09","tree-02-red","tree-07","tree-06","tree-06-brown", +"tree-09-brown","tree-09-red","tree-08","tree-08-brown","tree-08-red","dead-dry-hairy-tree","dead-grey-trunk", +"dead-tree-desert","dry-hairy-tree","dry-tree","rock-huge","rock-big","sand-rock-big","small-worm-turret", +"medium-worm-turret","big-worm-turret","behemoth-worm-turret","biter-spawner","spitter-spawner", +"crude-oil","coal","copper-ore","iron-ore","stone","uranium-ore", +} --game.entity_prototypes + +nauvis.ab={} local alienbiome=nauvis.ab +alienbiome.tile={ -- tile-alias.lua -- mod compatability -_- + ["grass-1"] = "vegetation-green-grass-1" , + ["grass-2"] = "vegetation-green-grass-2" , + ["grass-3"] = "vegetation-green-grass-3" , + ["grass-4"] = "vegetation-green-grass-4" , + ["dirt-1"] = "mineral-tan-dirt-1" , + ["dirt-2"] = "mineral-tan-dirt-2" , + ["dirt-3"] = "mineral-tan-dirt-1" , + ["dirt-4"] = "mineral-tan-dirt-2" , + ["dirt-5"] = "mineral-tan-dirt-3" , + ["dirt-6"] = "mineral-tan-dirt-5" , + ["dirt-7"] = "mineral-tan-dirt-4" , + ["dry-dirt"] = "mineral-tan-dirt-6" , + ["red-desert-0"] = "vegetation-olive-grass-2" , + ["red-desert-1"] = "mineral-brown-dirt-1" , + ["red-desert-2"] = "mineral-brown-dirt-5" , + ["red-desert-3"] = "mineral-brown-dirt-6" , + ["sand-1"] = "mineral-brown-sand-1" , + ["sand-2"] = "mineral-brown-sand-1" , + ["sand-3"] = "mineral-brown-sand-2" , + ["sand-4"] = "mineral-brown-sand-3" , } -planet.barren={ zone=12, rng=getrng("barren"), name="A Barren Planet", desc="This world looks deserted and we appear to be safe. .. For now.", - warp_multiply=0.25, - nowater=true, - gen={ - starting_area = "none", - --cliff_settings = { cliff_elevation_0 = 1024 }, - default_enable_all_autoplace_controls = false, - - autoplace_settings = { - decorative = { treat_missing_as_default = false,settings={ - ["trees"]={frequency=0,size=0,richness=0}, - ["rocks"]={frequency=2,size=2,richness=2} - } }, - entity = { treat_missing_as_default = false,settings={ - --["rock-huge-white"]={frequency=2,size=2,richness=2}, - ["rock-huge"]={frequency=2,size=2,richness=2}, - } }, - tile = { treat_missing_as_default = false, settings = { - ["sand-1"]=czControl(1,1,1),["sand-2"]=czControl(1,1,1),["sand-3"]=czControl(1,1,1), - ["dirt-1"]=czControl(1,1,1),["dirt-2"]=czControl(2,2,2),["dirt-3"]=czControl(), - ["dirt-4"]=czControl(),["dirt-5"]=czControl(),["dirt-6"]=czControl(),["dirt-7"]=czControl(), - ["dry-dirt"]=czControl(), - }, }, - }, - property_expression_names={ - --["entity:rock-huge-white:probability"]=1000, - --["decorative:rock-small-white:probability"]=1000, - }, - }, - fgen=function(t,b) +alienbiome.entities={ - end, - spawn=function(f) - f.daytime=0 - f.freeze_daytime=1 - f.peaceful_mode=1 - for k,v in pairs(f.find_entities_filtered{type="resource"})do v.destroy() end - end, } -for a,b in pairs({"rocks","sandrocks"})do - local v=decal[b] - for i,e in pairs(v)do planet.barren.gen.autoplace_settings.entity.settings[e]=czControl(1.5,1.5,1) end - for i,e in pairs(v)do planet.barren.gen.autoplace_settings.decorative.settings[e]=czControl(1.5,1.5,1) end -end --- if v.prototype.autoplace_specification +alienbiome.decor={ -planet.ocean={ zone=3, rng=getrng("ocean"), name="An Ocean Planet", desc="There is water all around and seems to go on forever. The nearby fish that greet you fills you with determination.", - warp_multiply=0.25, - gen={ starting_area="none",water=999999,default_enable_all_autoplace_controls=false,autoplace_controls={["trees"]={frequency=1,size=1,richness=1}},autoplace_settings={ - tile={treat_missing_as_default=false,settings={["water"]={frequency=5,size=5},["deepwater"]={frequency=5,size=5}}}, - entity={treat_missing_as_default=false,settings={["fish"]={frequency=5,size=5,richness=10}}},decorative = { treat_missing_as_default = false }, - }}, - spawn=function(f) end, } -planet.rich={ zone=60, rng=getrng("rich"), name="A Rich Planet", desc="A Rich Planet Description", - orig_mul=true, - gen={ - autoplace_controls={["iron-ore"]=new(czMeta,4,2,1),["enemy-base"]=new(czMeta,1.25,1.25), - ["copper-ore"]=new(czMeta,4,2),["coal"]=new(czMeta,4,2),["crude-oil"]=new(czMeta,4,2),["uranium-ore"]=new(czMeta,4,2),["stone"]=new(czMeta,4,2), - }, - }, - spawn=function(f) end, +alienbiome.noise={ + } --- -------- --- Resource Specific Planets +--[[ Lookup Functions ]]-- -planet.copper={ zone=8, rng=getrng("res"), name="A Copper Planet", desc="The warp reactor surges with power and you feel static in the air. You are filled with determination.", - warp_multiply=0.5, - orig_mul=true, - gen={ - autoplace_controls={["copper-ore"]=new(czMeta,4,2,1), - ["iron-ore"]=czIron,["coal"]=czCoal,["crude-oil"]=czRes,["uranium-ore"]=czRes,["stone"]=czRes, - }, - }, - --spawn=function(f) for k,v in pairs(f.find_entities_filtered{type="resource"})do if(v.name~="copper-ore")then v.destroy() end end end -} +function warptorio.GetAllResources() if(warptorio.AllResources)then return warptorio.AllResources end local pt=game.autoplace_control_prototypes local at={} + for k,v in pairs(pt)do if(v.category=="resource")then table.insert(at,v.name) end end warptorio.AllResources=at return at end +function warptorio.GetModResources() if(warptorio.ModResources)then return warptorio.ModResources end local pt=game.autoplace_control_prototypes local at={} + for k,v in pairs(pt)do if(v.category=="resource" and not table.HasValue(nauvis.resource,v.name))then table.insert(at,v.name) end end warptorio.ModResources=at return at end -planet.iron={ zone=5, rng=getrng("res"), name="An Iron Planet", desc="You land with a loud metal clang. The sparkle in the ground fills you with determination.", - orig_mul=true, - gen={ - autoplace_controls={["iron-ore"]=new(czMeta,4,2,1), - ["copper-ore"]=czCopper,["coal"]=czCoal,["crude-oil"]=czRes,["uranium-ore"]=czRes,["stone"]=czRes, - }, - }, - --spawn=function(f) for k,v in pairs(f.find_entities_filtered{type="resource"})do if(v.name~="iron-ore")then v.destroy() end end end, -} +function warptorio.CacheModTiles() if(warptorio.ModTiles)then return warptorio.ModTiles end local pt=game.tile_prototypes local at={} + for k,v in pairs(pt)do if(v.autoplace_specification and not table.HasValue(nauvis.tile,v.name) and not table.HasValue(nauvis.ab.tile,v.name) )then table.insert(at,v.name) end end warptorio.ModTiles=at return at end +function warptorio.CacheAllTiles() if(warptorio.AllTiles)then return warptorio.AllTiles end local pt=game.tile_prototypes local at={} + for k,v in pairs(pt)do if(v.autoplace_specification)then table.insert(at,v.name) end end warptorio.AllTiles=at return at end -planet.coal={ zone=7, rng=getrng("res"), name="A Coal Planet", desc="The piles of raw fuel strewn about this world makes you wonder about the grand forest that once thrived here, a very long time ago.", - orig_mul=true, - gen={ - autoplace_controls={["coal"]=new(czMeta,7,2,1), - ["iron-ore"]=czIron,["copper-ore"]=czCopper,["crude-oil"]=czRes,["uranium-ore"]=czRes,["stone"]=czRes - }, - }, - --spawn=function(f) for k,v in pairs(f.find_entities_filtered{type="resource"})do if(v.name~="coal")then v.destroy() end end end, -} +function warptorio.GetModTiles(n) local t=warptorio.CacheModTiles() if(not n or n==true)then return t else return table.GetMatchTable(t,n) end end +function warptorio.GetNauvisTiles(n) local t,tn=nauvis.tile if(warptorio.alienBiomes)then tn=t t=nauvis.ab.tile end if(not n or n==true)then return t end + if(tn)then + local y,x={},table.GetMatchTable(tn,n) + for k,v in pairs(x)do if(t[v])then table.insertExclusive(y,t[v]) end end + return y + end + return table.GetMatchTable(t,n) +end +function warptorio.GetTiles(n) local t=warptorio.CacheAllTiles() if(not n or n==true)then return t else return table.GetMatchTable(t,n) end end -planet.uranium={ zone=30, rng=getrng("res"), name="A Uranium Planet", desc="The warmth of this worlds green glow fills you with determination, but you probably shouldn't stay too long", - orig_mul=true, - gen={ - autoplace_controls={["uranium-ore"]=setmetatable({frequency=8,size=2,richness=1},czMeta),["enemy-base"]=setmetatable({frequency=1.5,size=1.5,richness=1},czMeta), - ["iron-ore"]=czIron,["copper-ore"]=czCopper,["coal"]=czCoal,["crude-oil"]=czRes,["stone"]=czRes, - }, - }, - --spawn=function(f) for k,v in pairs(f.find_entities_filtered{type="resource"})do if(v.name~="uranium-ore")then v.destroy() end end end, + +function warptorio.CacheModAutoplacers() if(warptorio.ModAutoplacers)then return warptorio.ModAutoplacers end local pt=game.autoplace_control_prototypes local at={} + for k,v in pairs(pt)do if(not table.HasValue(nauvis.autoplace,v.name) and v.category~="resource")then table.insert(at,v.name) end end warptorio.ModAutoplacers=at return at end +function warptorio.CacheAllAutoplacers() if(warptorio.AllAutoplacers)then return warptorio.AllAutoplacers end local pt=game.autoplace_control_prototypes local at={} + for k,v in pairs(pt)do if(v.category~="resource")then table.insert(at,v.name) end end warptorio.AllAutoplacers=at return at end + +function warptorio.GetModAutoplacers(n) local t=warptorio.CacheModAutoplacers() if(not n or n==true)then return t else return table.GetMatchTable(t,n) end end +function warptorio.GetNauvisAutoplacers(n) local t=nauvis.autoplace if(not n or n==true)then return t else return table.GetMatchTable(t,n) end end +function warptorio.GetAutoplacers(n) local t=warptorio.CacheAllAutoplacers() if(not n or n==true)then return t else return table.GetMatchTable(t,n) end end + +function warptorio.CacheModDecoratives() if(warptorio.ModDecoratives)then return warptorio.ModDecoratives end local pt=game.decorative_prototypes local at={} + for k,v in pairs(pt)do if(v.autoplace_specification and not table.HasValue(nauvis.decor,v.name) and not table.HasValue(nauvis.ab.decor,v.name) )then + table.insert(at,v.name) end end warptorio.ModDecoratives=at return at end +function warptorio.CacheAllDecoratives() if(warptorio.AllDecoratives)then return warptorio.AllDecoratives end local pt=game.decorative_prototypes local at={} + for k,v in pairs(pt)do if(v.autoplace_specification)then table.insert(at,v.name) end end warptorio.AllDecoratives=at return at end + +function warptorio.GetModDecoratives(n) local t=warptorio.CacheModDecoratives() if(not n or n==true)then return t else return table.GetMatchTable(t,n) end end +function warptorio.GetNauvisDecoratives(n) local t=nauvis.decor if(not n or n==true)then return t else return table.GetMatchTable(t,n) end end +function warptorio.GetDecoratives(n) local t=warptorio.CacheAllDecoratives() if(not n or n==true)then return t else return table.GetMatchTable(t,n) end end + +function warptorio.CacheModEntities() if(warptorio.ModEntities)then return warptorio.ModEntities end local pt=game.entity_prototypes local at={} + for k,v in pairs(pt)do if(v.autoplace_specification and not table.HasValue(nauvis.entities,v.name))then table.insert(at,v.name) end end warptorio.ModEntities=at return at end +function warptorio.CacheAllEntities() if(warptorio.AllEntities)then return warptorio.AllEntities end local pt=game.entity_prototypes local at={} + for k,v in pairs(pt)do if(v.autoplace_specification)then table.insert(at,v.name) end end warptorio.AllEntities=at return at end + +function warptorio.GetModEntities(n) local t=warptorio.CacheModEntities() if(not n or n==true)then return t else return table.GetMatchTable(t,n) end end +function warptorio.GetNauvisEntities(n) local t=nauvis.entities if(not n or n==true)then return t else return table.GetMatchTable(t,n) end end +function warptorio.GetEntities(n) local t=warptorio.CacheAllEntities() if(not n or n==true)then return t else return table.GetMatchTable(t,n) end end + + + + +--[[ Planet Control Data ]]-- + + +warptorio.Planets={} local pdata=warptorio.Planets -- planet data interface + +local function PCR(f,z,r) return {frequency=f or 1,size=z or f or 1,richness=r or f or 1} end +local function PCRMul(a,b) if(type(b)=="table")then + return {frequency=(a.frequency or 1)*(b.frequency or 1),size=(a.size or 1)*(b.size or 1),richness=(a.richness or 1)*(b.richness or 1)} else + return {frequency=(a.frequency or 1)*(b or 1),size=(a.size or 1)*(b or 1),richness=(a.richness or 1)*(b or 1)} +end end +local function PCRAdd(a,b) if(type(b)=="table")then + return {frequency=a.frequency+b.frequency,size=a.size+b.size,richness=a.richness+b.richness} else return {frequency=a.frequency+b,size=a.size+b,richness=a.richness+b} +end end + +warptorio.PlanetModifiers={} local pmods=warptorio.PlanetModifiers + +--[[ Basic Control Modifiers ]]-- + +pmods.water={ fgen=function(g,ev) g.water=ev return g end } -- {"water",10000} +pmods.biters={ fgen=function(g,ev) g.autoplace_controls["enemy-base"]=PCRMul(PCR(1),ev) return g end} -- {"biters",PCR(10,10,10)} +pmods.biters_multiply={ fgen=function(g,ev) g.autoplace_controls["enemy-base"]=PCRMul(g.autoplace_controls["enemy-base"] or PCR(1),ev) return g end} -- {"biters",PCR(10,10,10)} +pmods.biters_add={ fgen=function(g,ev) g.autoplace_controls["enemy-base"]=PCRAdd(g.autoplace_controls["enemy-base"] or PCR(1),ev) return g end} -- {"biters",PCR(10,10,10)} +pmods.biters_random={ fgen=function(g,ev) g.autoplace_controls["enemy-base"]= PCRMul( g.autoplace_controls["enemy-base"] or PCR(1),math.random(ev[1]*100,ev[2]*100)/100 ) return g end } + +pmods.trees={ fgen=function(g,ev) g.autoplace_controls.trees=PCRMul(PCR(1),ev) return g end } -- {"trees",PCR(1)} +pmods.trees_multiply={ fgen=function(g,ev) g.autoplace_controls.trees= PCRMul(g.autoplace_controls.trees or PCR(1),ev) return g end } +pmods.trees_add={ fgen=function(g,ev) g.autoplace_controls.trees=PCRAdd(g.autoplace_controls.trees or PCR(1),ev) return g end } +pmods.trees_random={ fgen=function(g,ev) g.autoplace_controls.trees= PCRMul( g.autoplace_controls.trees or PCR(1),math.random(ev[1]*100,ev[2]*100)/100 ) return g end } + +pmods.cliffs={ fgen=function(g,ev) g.cliffs=ev return g end } -- {"cliffs",{data here}} +pmods.starting_area={ fgen=function(g,ev) g.starting_area=ev return g end } +pmods.disable_all_defaults={gen={ default_enable_all_autoplace_controls=false, + autoplace_settings={ decorative={treat_missing_as_default=false},entity={treat_missing_as_default=false},tile={treat_missing_as_default=false} } +}} + +pmods.moisture={ fgen=function(g,ev) g.moisture=ev return g end} +pmods.aux={ fgen=function(g,ev) g.aux=ev return g end} +pmods.temperature={ fgen=function(g,ev) g.temperature=ev return g end} +pmods.elevation={ fgen=function(g,ev) g.elevation=ev return g end} +pmods.cliffiness={ fgen=function(g,ev) g.cliffiness=ev return g end} +pmods.aux={ fgen=function(g,ev) g.aux=ev return g end} + +pmods.property={ fgen=function(g,ev) g[ev[1]]=ev[2] end} + +--[[ Basic Spawn Modifiers ]]-- + +pmods.daytime={ spawn=function(f,g,ev,r) ev=ev or {} + if(ev.time)then f.daytime=ev.time end + if(ev.random)then f.daytime=math.random(ev.random[1]*100,ev.random[2]*100)/100 end + if(ev.freeze)then f.freeze_daytime=true end +end } -- {"daytime",{time=0,freeze=true}} + + +--[[ Resource Modifiers ]]-- +-- todo: similar searching to other modifiers + +pmods.resource_multiply_all={ fgen=function(g,ev) for k,v in pairs(warptorio.GetAllResources())do g.autoplace_controls[k]=PCRMul(g.autoplace_controls[k] or PCR(1),ev) end return g end } +pmods.resource_multiply={ fgen=function(g,ev) for k,v in pairs(ev)do g.autoplace_controls[k]=PCRMul(g.autoplace_controls[k] or PCR(1),v) end return g end } +pmods.resource_multiply_random={ + fgen=function(g,ev) local x,t={},table.deepcopy(warptorio.GetAllResources()) local c=math.min( (ev.count and ev.count or (ev.random and math.random(1,ev.random) or 1)), #t) + if(c>0)then for i=1,c,1 do local u=math.random(1,#t) table.insert(x,table.remove(t,u)) end for k,v in pairs(x)do + g.autoplace_controls[v]=PCRMul(g.autoplace_controls[v] or PCR(1),ev.value) + end end + return g,x + end +} -- Multiply a random resource. {"resource_multiply_random",{ (count=1 or random=2), value=PCR(2)}} + +pmods.resource_add_all={ fgen=function(g,ev) for k,v in pairs(warptorio.GetAllResources())do g.autoplace_controls[k]=PCRAdd(g.autoplace_controls[k] or PCR(1),ev) end return g end } +pmods.resource_add={ fgen=function(g,ev) for k,v in pairs(ev)do g.autoplace_controls[k]=PCRAdd(g.autoplace_controls[k] or PCR(1),v) end return g end } +pmods.resource_add_random={ + fgen=function(g,ev) local x,t={},table.deepcopy(warptorio.GetAllResources()) local c=math.min( (ev.count and ev.count or (ev.random and math.random(1,ev.random) or 1)), #t) + if(c>0)then for i=1,c,1 do local u=math.random(1,#t) table.insert(x,table.remove(t,u)) end + for k,v in pairs(x)do g.autoplace_controls[v]=PCRAdd(g.autoplace_controls[v] or PCR(1),ev.value) end end + return g,x + end +} -- Add a random resource. {"resource_add_random",{ (count=1 or random=2), value=PCR(2)}} + +pmods.resource_set_all={ fgen=function(g,ev) for k,v in pairs(warptorio.GetAllResources())do g.autoplace_controls[v]=ev end return g end } -- {"resource_set_all",PCR(1,2,3)} +pmods.resource_set={ fgen=function(g,ev) for k,v in pairs(ev)do g.autoplace_controls[k]=v end return g end } -- {"resource_set",{ ["iron-ore"]=PCR(4,3,2) } } +pmods.resource_set_random={ + fgen=function(g,ev) local x,t={},table.deepcopy(warptorio.GetAllResources()) local c=math.min( (ev.count and ev.count or (ev.random and math.random(1,ev.random) or 1)), #t) + if(c>0)then for i=1,c,1 do local u=math.random(1,#t) table.insert(x,table.remove(t,u)) end + for k,v in pairs(x)do g.autoplace_controls[v]=PCRMul(g.autoplace_controls[v] or PCR(1),ev.value) end end + return g,x + end +} -- Set a random resource. {"resource_set_random",{ (count=1 or random=2), value=PCR(0)}} + + +--[[ Decorative Modifiers ]]-- +-- todo: similar decorative searching to autoplacement, entity and tile modifiers + +pmods.rocks={ + fgen=function(g,ev) for k,v in pairs(game.decorative_prototypes)do if(v.autoplace_specification and v.name:match("rock"))then + g.autoplace_settings.decorative.settings[v.name]=PCRMul(PCR(1),ev) + end end return g end, +} +pmods.rocks_multiply={ + fgen=function(g,ev) for k,v in pairs(game.decorative_prototypes)do if(v.autoplace_specification and v.name:match("rock"))then + g.autoplace_settings.decorative.settings[v.name]=PCRMul(g.autoplace_settings.decorative.settings[v.name] or PCR(1),ev) + end end return g end, +} +pmods.decor={ + fgen=function(g,ev) for k,v in pairs(game.decorative_prototypes)do if(v.autoplace_specification and not v.name:match("rock"))then + g.autoplace_settings.decorative.settings[v.name]=PCRMul(PCR(1),ev) + end end return g end, +} +pmods.decor_multiply={ + fgen=function(g,ev) for k,v in pairs(game.decorative_prototypes)do if(v.autoplace_specification and not v.name:match("rock"))then + g.autoplace_settings.decorative.settings[v.name]=PCRMul(g.autoplace_settings.decorative.settings[v.name] or PCR(1),ev) + end end return g end, +} +pmods.decals={ + fgen=function(g,ev) for k,v in pairs(game.decorative_prototypes)do if(v.autoplace_specification and v.name:match(ev[1]))then + g.autoplace_settings.decorative.settings[v.name]=PCRMul(PCR(1),ev[2]) + end end return g end, +} +pmods.decals_multiply={ + fgen=function(g,ev) for k,v in pairs(game.decorative_prototypes)do if(v.autoplace_specification and v.name:match(ev[1]))then + g.autoplace_settings.decorative.settings[v.name]=PCRMul(g.autoplace_settings.decorative.settings[v.name] or PCR(1),ev[2]) + end end return g end, } -planet.oil={ zone=10, rng=getrng("res"), name="An Oil Planet", desc="This place has been a wellspring of life for millenia, and they might fuel your flamethrowers for the battles to come.", - orig_mul=true, - gen={ - autoplace_controls={["crude-oil"]=new(czMeta,7,2),["enemy-base"]=new(czMeta,1.25,1.25,1), - ["iron-ore"]=czIron,["copper-ore"]=czCopper,["coal"]=cRes,["stone"]=czRes,["uranium-ore"]=czRes - }, - }, - --spawn=function(f) for k,v in pairs(f.find_entities_filtered{type="resource"})do if(v.name~="crude-oil")then v.destroy() end end end, +pmods.decals_expr={ + fgen=function(g,ev) for k,v in pairs(game.decorative_prototypes)do if(v.autoplace_specification and v.name:match(ev[1]))then + g.property_expression_names[v.name .. ":" .. ev[2]]=ev[3] + end end return g end, +} +pmods.decals_expr_inv={ + fgen=function(g,ev) for k,v in pairs(game.decorative_prototypes)do if(v.autoplace_specification and not v.name:match(ev[1]))then + g.property_expression_names[v.name .. ":" .. ev[2]]=ev[3] + end end return g end, } +--[[ Autoplacement Modifiers ]]-- -planet.stone={ zone=15, rng=getrng("res"), name="A Stone Planet", desc="This planet is like your jouney through warpspacetime. Stuck somewhere between a rock and a hard place.", - orig_mul=true, - gen={ - autoplace_controls={["stone"]=new(czMeta,8,2), - ["iron-ore"]=czIron,["copper-ore"]=czCopper,["coal"]=czCoal,["crude-oil"]=czRes,["uranium-ore"]=czRes,["crude-oil"]=czRes, - }, - }, - --spawn=function(f) for k,v in pairs(f.find_entities_filtered{type="resource"})do if(v.name~="stone")then v.destroy() end end end, -} +pmods.autoplace={fgen=function(g,ev) for k,v in pairs(warptorio.GetAutoplacers(ev[1]))do g.autoplace_controls[v]=PCRMul(PCR(1),ev) end return g end,} +pmods.autoplace_multiply={fgen=function(g,ev) for k,v in pairs(warptorio.GetAutoplacers(ev[1]))do g.autoplace_controls[v]=PCRMul(g.autoplace_controls[v] or PCR(1),ev[2]) end return g end,} +pmods.autoplace_expr={fgen=function(g,ev) for k,v in pairs(warptorio.GetAutoplacers(ev[1]))do g.property_expression_names[v..":"..ev[2]]=PCRMul(PCR(1),ev[3]) end return g end,} +pmods.autoplace_nauvis={fgen=function(g,ev) for k,v in pairs(warptorio.GetNauvisAutoplacers(ev[1]))do g.autoplace_controls[v]=PCRMul(PCR(1),ev[2]) end return g end,} +pmods.autoplace_nauvis_multiply={fgen=function(g,ev) for k,v in pairs(warptorio.GetNauvisAutoplacers(ev[1]))do g.autoplace_controls[v]=PCRMul(g.autoplace_controls[v] or PCR(1),ev[2]) end return g end,} +pmods.autoplace_nauvis_expr={fgen=function(g,ev) for k,v in pairs(warptorio.GetNauvisAutoplacers(ev[1]))do g.property_expression_names[v..":"..ev[2]]=PCRMul(PCR(1),ev[3]) end return g end,} --- -------- --- Biter Planets +pmods.autoplace_mod={fgen=function(g,ev) for k,v in pairs(warptorio.GetModAutoplacers(ev[1]))do g.autoplace_controls[v]=PCRMul(PCR(1),ev[2]) end return g end,} +pmods.autoplace_mod_multiply={fgen=function(g,ev) for k,v in pairs(warptorio.GetModAutoplacers(ev[1]))do g.autoplace_controls[v]=PCRMul(g.autoplace_controls[v] or PCR(1),ev[2]) end return g end,} +pmods.autoplace_mod_expr={fgen=function(g,ev) for k,v in pairs(warptorio.GetNauvisAutoplacers(ev[1]))do g.property_expression_names[v..":"..ev[2]]=PCRMul(PCR(1),ev[3]) end return g end,} -planet.polluted={ zone=40,rng=getrng("polluted"),name="A Polluted Planet", desc="A heavy aroma of grease and machinery suddenly wafts over the platform and you wonder if you have been here before.", - warp_multiply=1.5, - orig_mul=true, - gen={ - autoplace_controls={["enemy-base"]=new(czMeta,1.75,1.75),}, - }, - spawn=function(f) - --f.daytime=0.5 - --f.freeze_daytime=0 - for x=-5,5,1 do for y=-5,5,1 do f.pollute({x*32,y*32},200) end end - end, -} +--[[ Entity Modifiers ]]-- -planet.midnight={ zone=20,rng=getrng("midnight"),name="A Planet Called Midnight", desc="Your hands disappear before your eyes as you are shrouded in darkness. This place seems dangerous.", - warp_multiply=1.5, - orig_mul=true, - gen={ - autoplace_controls={["enemy-base"]=new(czMeta,2,2),}, - }, - spawn=function(f) - f.daytime=0.5 - f.freeze_daytime=0 - end, -} +pmods.entity={fgen=function(g,ev) for k,v in pairs(warptorio.GetEntities(ev[1]))do g.autoplace_settings.entity.settings[v]=PCRMul(PCR(1),ev[2]) end return g end,} +pmods.entity_multiply={fgen=function(g,ev) for k,v in pairs(warptorio.GetEntities(ev[1]))do g.autoplace_settings.entity.settings[v]=PCRMul(g.autoplace_settings.entity.settings[v] or PCR(1),ev[2]) end return g end,} +pmods.entity_expr={ fgen=function(g,ev) for k,v in pairs(warptorio.GetEntities(ev[1]))do g.property_expression_names[v .. ":" .. ev[2]]=ev[3] end return g end,} +pmods.entity_mod={fgen=function(g,ev) for k,v in pairs(warptorio.GetModEntities(ev[1]))do g.autoplace_settings.entity.settings[v]=PCRMul(PCR(1),ev[2]) end return g end,} +pmods.entity_mod_multiply={fgen=function(g,ev) for k,v in pairs(warptorio.GetModEntities(ev[1]))do g.autoplace_settings.entity.settings[v]=PCRMul(g.autoplace_settings.entity.settings[v] or PCR(1),ev[2]) end return g end,} +pmods.entity_mod_expr={ fgen=function(g,ev) for k,v in pairs(warptorio.GetModEntities(ev[1]))do g.property_expression_names[v .. ":" .. ev[2]]=ev[3] end return g end,} -planet.biter={ zone=60,rng=getrng("biter"),name="A Biter Planet", desc="Within moments of warping in, your factory is immediately under siege. We must survive until the next warp!", - warp_multiply=1, - orig_mul=true, - gen={ - starting_area=0.3, - autoplace_controls={["enemy-base"]=new(czMeta,8,8),}, - }, -} +pmods.entity_nauvis={fgen=function(g,ev) for k,v in pairs(warptorio.GetNauvisEntities(ev[1]))do g.autoplace_settings.entity.settings[v]=PCRMul(PCR(1),ev[2]) end return g end,} +pmods.entity_nauvis_multiply={fgen=function(g,ev) for k,v in pairs(warptorio.GetNauvisEntities(ev[1]))do g.autoplace_settings.entity.settings[v]=PCRMul(g.autoplace_settings.entity.settings[v] or PCR(1),ev[2]) end return g end,} +pmods.entity_nauvis_expr={ fgen=function(g,ev) for k,v in pairs(warptorio.GetNauvisEntities(ev[1]))do g.property_expression_names[v .. ":" .. ev[2]]=ev[3] end return g end,} -planet.rogue={ zone=100,rng=getrng("rogue"),name="A Rogue Planet", desc="Ah, just your usual barren wasteland, nothing to worry about. But something seems a little off.", - warp_multiply=1, - orig_mul=false, - nowater=true, - gen={ - starting_area=2.5, - autoplace_controls={["enemy-base"]=new(czMeta,3,3,1),["trees"]=new(czMeta,3,0.25,0.25), ["dirt"]=new(czMeta,4,4,4),["sand"]=new(czMeta,4,4,4)}, - autoplace_settings = { - decorative = { treat_missing_as_default = false,settings={} }, - entity = { treat_missing_as_default = true,settings={} }, - tile = { treat_missing_as_default = false, settings = {}, }, - }, - default_enable_all_autoplace_controls = true - }, - fgen=function(t,b) local x=t.autoplace_settings.tile.settings local y={frequency="very-low",size=2} - for i=1,3,1 do x["sand-"..i]=y end - for i=1,7,1 do x["dirt-"..i]=y end - x["dry-dirt"]=y x["sand-decal"]=y x["sand-dune-decal"]=y - if(b)then end - end, - spawn=function(f) - f.daytime=0.5 - f.freeze_daytime=0 - end, +--[[ Tile Modifiers ]]-- + +pmods.tile_mod={ fgen=function(g,ev) for k,v in pairs(warptorio.GetModTiles(ev[1]))do g.autoplace_settings.tile.settings[v]=(ev[2]==true and {} or (ev[2]==false and nil or PCRMul(g.autoplace_settings.tile.settings[v] or PCR(1),ev[2]))) end return g end } +pmods.tile_nauvis={ fgen=function(g,ev) for k,v in pairs(warptorio.GetNauvisTiles(ev[1]))do g.autoplace_settings.tile.settings[v]=(ev[2]==true and {} or (ev[2]==false and nil or PCRMul(g.autoplace_settings.tile.settings[v] or PCR(1),ev[2]))) end return g end } +pmods.tile={ fgen=function(g,ev) for k,v in pairs(warptorio.GetTiles(ev[1]))do g.autoplace_settings.tile.settings[v]=(ev[2]==true and {} or (ev[2]==false and nil or PCRMul(g.autoplace_settings.tile.settings[v] or PCR(1),ev[2]))) end return g end } + +pmods.tile_nauvis_expr={ fgen=function(g,ev) for k,v in pairs(warptorio.GetNauvisTiles(ev[1]))do g.property_expression_names["tile:"..v..":"..ev[2]]=ev[3] end return g end } +pmods.tile_mod_expr={ fgen=function(g,ev) for k,v in pairs(warptorio.GetModTiles(ev[1]))do g.property_expression_names["tile:"..v..":"..ev[2]]=ev[3] end return g end } +pmods.tile_expr={ fgen=function(g,ev) for k,v in pairs(warptorio.GetTiles(ev[1]))do g.property_expression_names["tile:"..v..":"..ev[2]]=ev[3] end return g end } + + +--[[ Nauvis Modifier -- Remove all other tiles, decorations, entities and autoplacers except nauvis ones ]] + + +pmods.nauvis={ -- remove mod tiles, decoratives and autoplacements + fgen=function(g,ev) ev=ev or {} + --[[if(ev.tiles~=false)then for k,v in pairs(warptorio.GetModTiles())do g.autoplace_settings.tile.settings[v]=g.autoplace_settings.tile.settings[v] or PCR(0) end end + if(ev.decor~=false)then for k,v in pairs(warptorio.GetModDecoratives())do g.autoplace_settings.decorative.settings[v]=g.autoplace_settings.decorative[v] or PCR(0) end end + if(ev.autop~=false)then for k,v in pairs(warptorio.GetModAutoplacers())do g.autoplace_controls[v]=g.autoplace_controls[v] or PCR(0) end end]] + + g.default_enable_all_autoplace_controls=false + g.autoplace_settings.decorative.treat_missing_as_default=false + g.autoplace_settings.entity.treat_missing_as_default=false + g.autoplace_settings.tile.treat_missing_as_default=false + + if(ev.tiles~=false)then for k,v in pairs(warptorio.GetNauvisTiles(ev.tiles))do g.autoplace_settings.tile.settings[v]={} end end + if(ev.decor~=false)then for k,v in pairs(warptorio.GetDecoratives(ev.decor))do g.autoplace_settings.decorative.settings[v]={} end end + if(ev.ents~=false)then for k,v in pairs(warptorio.GetEntities(ev.ents))do g.autoplace_settings.entity.settings[v]={} end end + if(ev.autoplace~=false)then for k,v in pairs(warptorio.GetNauvisAutoplacers(ev.autoplace))do g.autoplace_controls[v]={} end end + if(ev.oremod~=false)then for k,v in pairs(warptorio.GetAllResources())do g.autoplace_controls[v]={} end end + + return g + end } -for a,b in pairs({"rocks","sandrocks","bush"})do - local v=decal[b] - for i,e in pairs(v)do planet.rogue.gen.autoplace_settings.entity.settings[e]=czControl(1.5,1.5,1) end - for i,e in pairs(v)do planet.rogue.gen.autoplace_settings.decorative.settings[e]=czControl(1.5,1.5,1) end + + +--[[ map_gen_settings Generator ]]-- + +warptorio.TileDefaults={} +function warptorio.TileDefault(n,b) + warptorio.TileDefaults[n]=b end -for k,v in pairs(warptorio.OreTypes)do - planet.rogue.gen.autoplace_controls[v]={size=0} + +function warptorio.RegisterPlanet(p) + warptorio.Planets[p.key]=table.deepcopy(p) + if(game and warptorio.Loaded)then for k,v in pairs(game.players)do warptorio.BuildGui(v) end end end +local mapgen={} warptorio.Mapgen=mapgen + +function warptorio.GeneratePlanetSettings(p,chart) + local g=mapgen.EmptyTable() + mapgen.ApplyModifiers(p,g,chart) + return g +end + +function warptorio.GeneratePlanetSurface(p,g,chart) + local f=game.create_surface("warpsurf_"..gwarptorio.warpzone,g) + f.request_to_generate_chunks({0,0},5) f.force_generate_chunk_requests() + + if(p.modifiers)then for k,v in ipairs(p.modifiers)do + local mod=warptorio.PlanetModifiers[v[1]] + if(mod.spawn_call)then remote.call(mod.spawn_call[1],mod.spawn_call[2],v[2],chart) + elseif(mod.spawn)then mod.spawn(f,g,v[2],r) end + end end + if(p.spawn_call)then + local r=remote.call(p.spawn_call[1],p.spawn_call[2],f,g,chart) + elseif(p.spawn)then p.spawn(f,g,chart) + end + + return f +end + +function warptorio.CheckPlanetControls(t) -- mod compatability -_- + local pt=game.autoplace_control_prototypes + if(warptorio.alienBiomes)then warptorio.DoAlienBiomesTiles(t) end + for k,v in pairs(t.autoplace_controls)do if(not pt[k])then t.autoplace_controls[k]=nil end end +end + +function mapgen.EmptyTable() + local t={ + seed=math.random(4294967295), + autoplace_controls={}, + autoplace_settings={tile={settings={}},entity={settings={}},decorative={settings={}} }, + property_expression_names={}, + } + for k,v in pairs(warptorio.TileDefaults)do if(v==false)then t.property_expression_names["tile:"..k..":probability"]=-1000000 end end + return t +end + +function mapgen.MergeSettings(g,gx) + return table.deepmerge(g,gx) +end +function mapgen.ApplyModifiers(p,g,chart) + if(p.modifiers)then for k,v in ipairs(p.modifiers)do + local mod=warptorio.PlanetModifiers[v[1]] + if(not mod)then error("Warptorio Planet Error (" .. p.key .. "): \"" .. v[1] .. "\" Modifier not found.") return g end + if(mod.gen)then mapgen.MergeSettings(g,mod.gen) end + if(mod.fgen_call)then + local r=remote.call(mod.fgen_call[1],mod.fgen_call[2],g,v[2],chart) + if(not r)then ErrorNoHalt("Warptorio Planet Error (".. p.key .. "): Remote \"" .. mod.fgen_call[1] .. "\".\"" .. mod.fgen_call[2] .. "\" did not return anything") return g end + mapgen.MergeSettings(g,r) + elseif(mod.fgen)then --game.print("applying modifier: " .. v[1]) + mapgen.MergeSettings(g,mod.fgen(g,v[2],chart)) + end + end end + if(p.nauvis_multiply~=false)then + local nvs=game.surfaces["nauvis"].map_gen_settings + for k,v in pairs(nvs.autoplace_controls)do + if(g.autoplace_controls[k])then g.autoplace_controls[k]=PCRMul(v,g.autoplace_controls[k]) end + end + if(g.starting_area)then g.starting_area=g.starting_area*(nvs.starting_area or 1) end + if(g.water)then g.water=g.water*(nvs.water or 1) end + end + if(p.fgen_call)then + mapgen.MergeSettings(g,remote.call(p.fgen_call[1],p.fgen_call[2],g)) + end + return g +end + + +--[[ Planet Tables ]]-- + +warptorio.RegisterPlanet({ + key="normal", name="A Normal Planet", zone=0, rng=PlanetRNG("normal"), + desc="This world reminds you of home.", + modifiers={{"nauvis"}}, + gen=nil, -- The base planet map_gen_settings table + + tick_speed=nil, -- =(60*60*minutes) -- runs the tick calls every X ticks + required_controls=nil, -- {"iron-ore"} -- Mod compatability: This planet REQUIRES a certain autoplace_control. + required_tiles=nil, -- {"grass-1"} -- Mod compatability: This planet REQUIRES a certain autoplace_setting.tile + required_ents=nil, -- {"enemy-base"} -- Mod compatability: This planet REQUIRES a certain autoplace_setting.entity + required_decor=nil, -- {"shrub-x"} -- Mod compatability: This planet REQUIRES a certain autoplace_setting.decorative + + -- Call tables are used for remote interfaces: { {"remote_interface","remote_name"} } + fgen_call=nil, -- Final function calls on map_gen_settings, behaving similar to a modifier function but planet specific. + spawn_call=nil, -- Function calls after surface is created. + tick_call=nil, -- Function calls per tick + chunk_call=nil, -- Functions called when a chunk is generated on the planet + warpout_call=nil, -- Function called upon warpout of this planet event{oldsurface=surface,oldplanet=planet_table,newsurface=surface,newplanet=planet_table} + postwarpout_call=nil, -- Function called upon warpout of this planet event{oldsurface=surface,oldplanet=planet_table,newsurface=surface,newplanet=planet_table} + + fgen=nil, -- function(map_gen_settings) end, -- planet modify function (warptorio internal) + spawn=nil, -- function(surface_object, table_of_modifier_return_values) -- planet spawn function (warptorio internal) + tick=nil, -- function(surface_object, event_variable) -- planet tick function (warptorio internal) + chunk=nil, -- function(surface_object, event_variable) -- planet on_chunk_generated function (warptorio internal) + warpout=nil, -- function(oldsurface,oldplanet,newsurface,newplanet) -- planet on warpout (warptorio internal) + postwarpout=nil, -- function(oldsurface,oldplanet,newsurface,newplanet) -- planet on warpout (warptorio internal) +}) + +warptorio.RegisterPlanet({ key="uncharted", name="An Uncharted Planet", zone=1, rng=PlanetRNG("uncharted"), -- default nauvis generation (modded) + desc="You prospect your surroundings and gaze at the stars, and you wonder if this world has ever had a name.", +}) + + +warptorio.RegisterPlanet({ key="average", name="An Average Planet", zone=3,rng=PlanetRNG("average"), + desc="The usual critters and riches surrounds you, but you feel like something is missing.", + modifiers={{"nauvis"},{"resource_set_random",{random=2,value=0}}}, +}) + +warptorio.RegisterPlanet({ + key="barren", name="A Barren Planet", zone=12, rng=PlanetRNG("barren"), warptime=0.5, nowater=true, + desc="This world looks deserted and we appear to be safe. .. For now.", + modifiers={ + {"nauvis",{tiles={"dirt","sand"},ents={"rock"},decor={"rock"},autoplace=false}}, + {"water",0}, + {"rocks",PCR(2,2,1)}, + {"entity",{{"rock"},PCR(2,2,1)}}, + }, +}) + +warptorio.RegisterPlanet({ + key="ocean", name="An Ocean Planet", zone=3, rng=PlanetRNG("ocean"), warptime=0.5, + desc="There is water all around and seems to go on forever. The nearby fish that greet you fills you with determination.", + modifiers={ + {"nauvis",{tiles={"grass","water"},ents={"fish","tree","trunk"},autoplace={"tree"}}}, + {"rocks",0}, + {"trees",PCR(3.25,0.1,0.3)}, + {"entity",{"tree",PCR(3.25,0.1,0.3)}}, + {"water",100000}, + {"starting_area",0}, + {"entity",{"fish",8}} + }, +}) + +warptorio.RegisterPlanet({ + key="jungle", name="A Jungle Planet", zone=27, rng=PlanetRNG("jungle"), warptime=1, + desc="These trees might be enough to conceal your location from the natives. .. At least for a while.", + modifiers={ + {"nauvis"}, + {"resource_set_all",0.5}, + {"trees",PCR(18,0.5,0.4)}, + {"entity",{"tree",PCR(26,0.55,0.4)}}, + {"starting_area",0.7}, + {"moisture",0.7}, + {"temperature",9}, + {"aux",0.1}, + {"daytime",{random={0,1}}}, + }, +}) + +warptorio.RegisterPlanet({ + key="dwarf", name="A Dwarf Planet", zone=12, rng=PlanetRNG("dwarf"), warptime=1, + desc="You are like a giant to the creatures of this planet. .. And to its natural resources.", + modifiers={{"nauvis"},{"resource_set_all",0.35},{"biters",PCR(0.5,0.5,1)}}, +}) + +warptorio.RegisterPlanet({ + key="rich", name="A Rich Planet", zone=60, rng=PlanetRNG("rich"), warptime=1, + desc="A Rich Planet Description", + modifiers={{"nauvis"},{"resource_set_all",PCR(4,2,1)},{"biters",PCR(1.25)}}, +}) + +warptorio.RegisterPlanet({ + key="iron", name="An Iron Planet", zone=5, rng=PlanetRNG("res"), warptime=1, + desc="You land with a loud metal clang. The sparkle in the ground fills you with determination.", + modifiers={ {"nauvis"},{"resource_set_all",0.3},{"resource_set",{["iron-ore"]=PCR(4,2,1)}} }, + required_controls={"iron-ore"}, +}) + +warptorio.RegisterPlanet({ + key="copper", name="A Copper Planet", zone=8, rng=PlanetRNG("res"), warptime=1, + desc="The warp reactor surges with power and you feel static in the air. You are filled with determination.", + modifiers={ {"nauvis"},{"resource_set_all",0.3},{"resource_set",{["copper-ore"]=PCR(4,2,1)}} }, + required_controls={"copper-ore"}, +}) + +warptorio.RegisterPlanet({ + key="coal", name="A Coal Planet", zone=7, rng=PlanetRNG("res"), warptime=1, + desc="The piles of raw fuel strewn about this world makes you wonder about the grand forest that once thrived here, a very long time ago.", + modifiers={ {"nauvis"},{"resource_set_all",0.3},{"resource_set",{["coal"]=PCR(7,2,1)}} }, + required_controls={"coal"}, +}) + +warptorio.RegisterPlanet({ + key="stone", name="A Stone Planet", zone=15, rng=PlanetRNG("res"), warptime=1, + desc="This planet is like your jouney through warpspacetime. Stuck somewhere between a rock and a hard place.", + modifiers={ {"nauvis"},{"resource_set_all",0.3},{"resource_set",{["crude-oil"]=PCR(7,2,1)}} }, + required_controls={"stone"}, +}) + +warptorio.RegisterPlanet({ + key="oil", name="An Oil Planet", zone=15, rng=PlanetRNG("res"), warptime=1, + desc="This place has been a wellspring of life for millenia, but now they are just more fuel for your flamethrowers.", + modifiers={ {"nauvis"},{"resource_set_all",0.3},{"resource_set",{["crude-oil"]=PCR(7,2,1)}},{"biters",PCR(1.15,1.15,1)} }, + required_controls={"crude-oil"}, +}) + +warptorio.RegisterPlanet({ + key="uranium", name="A Uranium Planet", zone=30, rng=PlanetRNG("res"), warptime=1, + desc="The warmth of this worlds green glow fills you with determination, but you probably shouldn't stay too long", + modifiers={ {"nauvis"},{"resource_set_all",0.3},{"resource_set",{["uranium-ore"]=PCR(8,2,1)}},{"biters",PCR(1.35,1.35,1)} }, + required_controls={"uranium-ore"}, +}) + +warptorio.RegisterPlanet({ + key="midnight", name="A Planet Called Midnight", zone=20, rng=PlanetRNG("midnight"), warptime=1.5, + desc="Your hands disappear before your eyes as you are shrouded in darkness. This place seems dangerous.", + modifiers={ {"nauvis"},{"biters",PCR(2)},{"daytime",{time=0.5,freeze=true}} }, +}) + +warptorio.RegisterPlanet({ + key="polluted", name="A Polluted Planet", zone=40, rng=PlanetRNG("polluted"), warptime=1.5, + desc="A heavy aroma of grease and machinery suddenly wafts over the platform and you wonder if you have been here before.", + modifiers={ {"nauvis"},{"resource_set_all",0.75},{"biters",PCR(1.75)} }, + spawn=function(f,g,chart) + for x=-5,5,1 do for y=-5,5,1 do f.pollute({x*32,y*32},200) end end + end, +}) + +warptorio.RegisterPlanet({ + key="biter", name="A Biter Planet", zone=60, rng=PlanetRNG("biter"), warptime=1.2, + desc="Within moments of warping in, your factory is immediately under siege. We must survive until the next warp!", + modifiers={ {"nauvis"},{"biters",PCR(8)},{"starting_area",0.3} }, +}) + +warptorio.RegisterPlanet({ + key="rogue", name="A Rogue Planet", zone=100, rng=PlanetRNG("rogue"), warptime=1.25, nowater=true, + desc="Ah, just your usual barren wasteland, nothing to worry about. But something seems a little off.", + modifiers={ + {"nauvis",{tiles={"dirt","sand"},decor={"rock"}}}, + {"resource_set_all",0}, + {"decor",PCR(0.1,0.1,0.1)}, + {"water",0}, + {"starting_area",1.8}, + {"biters",3}, + {"rocks",PCR(2,2,1)}, + {"entity",{{"rock"},PCR(2,2,1)}}, + + {"trees",PCR(1.25,0.075,0.3)}, + {"entity",{"tree",PCR(1.25,0.075,0.3)}}, + {"daytime",{time=0.35,freeze=true}}, + }, +}) + +--[[warptorio.RegisterPlanet({ + key="void", name="Warpspace Void", zone=50, rng=PlanetRNG("void"), warptime=1.75, nowater=true, + desc="What on earth was that, where are we!? Something went wrong with the warp reactor and we are stranded in a vast nothingness.", + modifiers={{"nauvis",{tiles={"dirt","sand"}}},{"water",0},{"starting_area",2.5},{"biters",3}}, +})]] -for k,v in pairs(planet)do v.key=k end diff --git a/data-updates.lua b/data-updates.lua index 3b6fad2..55aab8b 100644 --- a/data-updates.lua +++ b/data-updates.lua @@ -1,3 +1,11 @@ +--[[ + +Add research for mod loaders + +]] + + + --[[ Add emissions to all entities @@ -80,3 +88,4 @@ for u,n in pairs(entTbl)do end --error(s) + diff --git a/data.lua b/data.lua index fe9229d..d42c416 100644 --- a/data.lua +++ b/data.lua @@ -6,6 +6,8 @@ require("data_warptorio-logistics-pipe") require("data_warptorio-warpstation") require("data_warpnuke") require("data_warptorio-warploader") +require("data_warptorio-townportal") +--require("data_nauvis_preset") local function istable(t) return type(t)=="table" end local function rgb(r,g,b,a) a=a or 255 return {r=r/255,g=g/255,b=b/255,a=a/255} end @@ -387,7 +389,7 @@ local t={type="technology",upgrade=true,icon_size=128,icons={ {icon="__base__/graphics/technology/nuclear-power.png",tint={r=0.3,g=0.3,b=1,a=1},priority="low"}, {icon="__base__/graphics/technology/atomic-bomb.png",tint={r=0.7,g=0.7,b=1,a=1},scale=0.5,shift={32,32},priority="high"} }, } -ExtendTech(t,{name="warptorio-reactor-6",unit={count=100,time=90}, prerequisites={"warptorio-reactor-5","uranium-processing","robotics"}}, {red=5,black=5}) -- reactor module +ExtendTech(t,{name="warptorio-reactor-6",unit={count=100,time=90}, effects={{recipe="warptorio-townportal",type="unlock-recipe"}},prerequisites={"warptorio-reactor-5","uranium-processing","robotics"}}, {red=5,black=5}) -- reactor module local t={type="technology",upgrade=true,icon_size=128,icons={ {icon="__base__/graphics/technology/nuclear-power.png",tint={r=0.3,g=0.3,b=1,a=1},priority="low"}, diff --git a/data_warptorio-heatpipe.lua b/data_warptorio-heatpipe.lua index 76b7e06..946a80c 100644 --- a/data_warptorio-heatpipe.lua +++ b/data_warptorio-heatpipe.lua @@ -1325,7 +1325,7 @@ data:extend{ max_health = 200, minable = { mining_time = 0.1, - result = "heat-pipe" + result = "warptorio-heatpipe" }, minimum_glow_temperature = 350, name = "warptorio-heatpipe", diff --git a/data_warptorio-townportal.lua b/data_warptorio-townportal.lua new file mode 100644 index 0000000..f5b51d0 --- /dev/null +++ b/data_warptorio-townportal.lua @@ -0,0 +1,47 @@ +local rtint={r=0.4,g=0.4,b=1,a=1} + +local rsc=1.5 + +data:extend{ + +{ + capsule_action = { + attack_parameters={type="stream",range=0,cooldown=10,ammo_category="capsule", + ammo_type={action={action_deliver={target_effects={damage={amount=-10,type="physical"},type="damage"},type="instant"},type="direct"},category="capsule",target_type="position"}, + }, + type = "use-on-self", + uses_stack=true, + }, + icons = {{icon="__warptorio2__/graphics/technology/earth.png",scale=1}}, + icon_size = 128, + name = "warptorio-townportal", + order = "zz", + stack_size = 5, + subgroup = "capsule", + type = "capsule" +}, + + +{ + enabled = false, + ingredients = { + { + "advanced-circuit", + 10 + }, + { + "grenade", + 10 + }, + { + "radar", + 10 + }, + }, + name = "warptorio-townportal", + result = "warptorio-townportal", + type = "recipe" +}, + + +} \ No newline at end of file diff --git a/data_warptorio-warploader.lua b/data_warptorio-warploader.lua index 2c71d25..e44d865 100644 --- a/data_warptorio-warploader.lua +++ b/data_warptorio-warploader.lua @@ -9,7 +9,7 @@ data:extend{ }, { name="warptorio-warploader", type="recipe",category="crafting-with-fluid",enabled=false,energy_required=2, - ingredients={ {"iron-gear-wheel",400},{"express-underground-belt",50},{amount=200,name="lubricant",type="fluid"} }, + ingredients={ {"iron-gear-wheel",400},{"express-underground-belt",50},{"express-transport-belt",100},{"express-splitter",50},{amount=200,name="lubricant",type="fluid"} }, result="warptorio-warploader",result_count=1, }, diff --git a/info.json b/info.json index c2d584c..2f54f24 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "warptorio2", - "version": "0.6.1", + "version": "0.7.4", "title": "Warptorio", "author": "Nonoce and PyroFire", "dependencies": ["base >= 0.17","! NewGamePlus","! Space Exploration"], diff --git a/settings.lua b/settings.lua index 3d0adc9..f32ae13 100644 --- a/settings.lua +++ b/settings.lua @@ -23,7 +23,9 @@ data:extend( allowed_values={"logistic-chest-requester","logistic-chest-buffer"}, }, - + {type="int-setting",name="warptorio_warpchance",order="aab3a", + setting_type="runtime-global",default_value=30, + minimum_value=1,maximum_value=100}, {type="bool-setting",name="warptorio_autowarp_always",order="aaba", setting_type="runtime-global",default_value=false,}, @@ -130,10 +132,22 @@ data:extend( setting_type="runtime-global",default_value=2, minimum_value=1,maximum_value=30}, - {type="int-setting",name="warptorio_planet_normal",order="ea", - setting_type="startup",default_value=23, + + + --[[ used in nauvis preset -- unused -- {type="int-setting",name="warptorio_nauvis_override",order="e1aa", + setting_type="startup",default_value=12, + minimum_value=1},]] + + + {type="int-setting",name="warptorio_planet_normal",order="eaa", + setting_type="startup",default_value=12, + minimum_value=1}, + + {type="int-setting",name="warptorio_planet_uncharted",order="eab", + setting_type="startup",default_value=12, minimum_value=1}, + {type="int-setting",name="warptorio_planet_average",order="eb", setting_type="startup",default_value=17, minimum_value=0}, @@ -178,5 +192,8 @@ data:extend( setting_type="startup",default_value=4, minimum_value=0}, + --[[ {type="int-setting",name="warptorio_planet_void",order="em", + setting_type="startup",default_value=1, + minimum_value=0}, ]] }) \ No newline at end of file