oops; think I took the wrong board; if a mod can switch the post to the right; would be nice
Just started another playthrough last night with Bob & Angel overhaul on 0.15; and had some thought about a new mod.
But to be honest, I dont really know if its actually possible to creat a mod like this; so I just share the Idea here; maybe some1 is willing to create something like this; or could lend me a hand or seven, if I would start create a mod.
I thought about a "population mod". Every Building has a defined amount of "people" working in it. Sciencecenter adds like +10 Population, a Boiler +3 and an assembler +15 or something like this.
Then it would need some more Buildings; like baracks; so one must have enought Space for all the workers in his big Facility (denie or deactivate new workplaces until there are enough beds in baracks)
Communitybuildings like a Taverne Sportcenter, Church, whatever, for pushing the will to work because "they" are more happy.
And at least a new line of products; producing food / drinkable water. Like the Greenhouse / Waterpump. If food or drinks are 0, the population begins to decrease until whole facility stands still.
In my eye there isnt a need of new graphics and ppl walking through the facility. Its just that I like the mechanism overall it would give to the whole thing.
Is something like this even possible in a mod? Or would that be a too big overhaul and is far over the top of the mod possibilities?
What are your thoughts about something like this? Yay or nay?
/discuss
Re: [Request/Idea] Population Mod
Posted: Sat Sep 23, 2017 9:02 pm
by Adil
Without the graphics or people movement simulations it is simplistic to the point of triviality:
BUILDINGS={
["laboratory"]={need={beds=10},give={}},
['green-house']={need={beds=5},give={food=40}},
['water-well']={need={beds=1},give={water=50}},
['church']={need={beds=3},give={happiness=30}},
['habitat']={need={},give={beds=20}}
}
script.on_init(function()
global.buildings={}
global.active_index=0
global.have={
beds=100,
food=100,
water=100,
happiness=100
}
global.satisfaction=1--multiplier for beds, pool
end)
local effects={
add=function(effects)
local have=global.have
for k,v in pairs(effects.give) do
have[k]=have[k]+v
end
end,
rem=function(effects)
local have=global.have
for k,v in pairs(effects.give) do
have[k]=have[k]-v
end
end
take=function(effects,pool)
local satisfied=true
for k,v in pairs(effects.need) do
pool[k]=pool[k]-v
satisfied=pool[k]>0
end
return satisfied
end,
}
building={
add=function(ent)--create record for building comprised of its entity and effects
local effects=BUILDINGS[ent.name]
if not effects then return end
local b={
entity=ent,
active=true,--this is shortcut to avoid calling factorio api without need, (maybe it is faster, not verified)
effects=effects--this is shortcut to the location of the associated effects
}
effects.add(effects)
table.insert(global.buildings,b)
end,
rem=function(ent)--remove building record by its entity
if not BUILDINGS[ent.name] then return end
local buildings=global.buildings
for i=#buildings,1,-1 do
if buildings[i].entity==e then
effects.rem(buildings[i].effects)
table.remove(buildings,i)
break
end
end
end,
activate=function(building)
if building.active then return end
building.active=true
building.entity.active=true
effects.add(building.effects)
end,
deactivate=function(building)
if not building.active then return end
building.active=false
building.entity.active=false
effects.rem(building.effects)
end,
}
local min=function(a,b) return (a<b) and a or b end
function recalculate_state()
local have=global.have
local pool={}--define available pool
for k,v in pairs(have) do
pool[k]=v
end
pool.beds=pool.beds*global.satisfaction
local buildings=global.buildings
for i=1,#buildings do--each building takes from pool
local b=buildings[i]
building.activate(b)
local satisfied = effects.take(b.effects,pool)
if not satisfied then building.deactivate(b) end--when no resources, work stops
end
local population=have.beds-pool.beds
local wm=min ((pool.water-population),0)/population
local fm=min ((pool.food-population),0)/population
local hm=min ((pool.happiness-population),0)/population
global.satisfaction=wm*fm*hm^2
end
local ev=defines.events
--without other mods intervention and without more complicated mechanics of resources in this mod
--these events are the only ones, that would cause the change in the state of the buildings
script.on_event({ev.on_built_entity,ev.on_robot_built_entity},function(event)
building.add(event.created_entity)
recalculate_state()
end)
script.on_event({ev.on_entity_died,ev.on_player_mined_entity,ev.on_robot_mined_entity},
function(event)
building.rem(event.entity)
recalculate_state()
end)
The last thing to do is to declare the new buildings prototypes and to fill out their consumption/yield table.
But without the visualization and without the calculation of population distribution in space that mechanic degrades to a simple equivalent of some building cap.
In general, you can implement pretty much any mechanic you want, lua inside the factorio is as turing-complete as any other language. The problems start when you need to express that mechanic through means of the factorio api and want to do that efficiently. (The code above would become notably more convoluted if I'd tried to remove not very efficient cycle from `recalculate_state`.)
Re: [Request/Idea] Population Mod
Posted: Sat Sep 23, 2017 10:43 pm
by foodfactorio
hi, this sounds interesting
without wishing to pinch your thread, id just like to post a link to a mod idea i posted some time ago that could maybe be related in some way (at least for the prestige part) which was a Colony mod idea: viewtopic.php?f=33&t=50256
(its also cool that you got a quick reply with some possible code maybe Adil if you have a spare few moments you could have a quick look there too, just to see if something on the colony mod idea is feasible or possible in some way? and maybe a future mod could possibly utilise some elements of each to make up a nice complimentary mod of some sort?
Re: [Request/Idea] Population Mod
Posted: Fri Sep 29, 2017 7:39 am
by doppelEben
Wow! Thanks for the response and the code-snipped. Very appreciate it. I'm looking through it and try to tinker something like I thought.