Jump to content

Recommended Posts

I'm searching since hours the game scripts... but I don't know how to get all active rooms (worldgeneration) ?!

We have the rooms.lua file, which adds all rooms to the variable "rooms". But it does not return this variable >.<
So how to get them all?


And does someone knows what
room.contents.distributepercent
does?
I would like to add some prefabs to existing rooms, with changing in AddRoomPreInit
room.contents.distributeprefabs.prefab = x
But it seems that x has a different result for each room? A value of 0.5 on grass seems to spawn much more things, than 0.5 on forest. Why?
 

Edited by Serpens
local function GetRoomsTable()
	local debug = GLOBAL.debug
	local func = GLOBAL.AddRoom
	local i = 1
	while true do
		local n, v = debug.getupvalue(func, i)
		if not n then
			return {}
		end
		if n == "rooms" then
			return v
		end
		i = i + 1
	end
end

local rooms = GetRoomsTable()

With this.

 

A room has points, positions that you have to fill.

How many of those points? That's determined by distributepercent.

The higher the distributepercent, the more points will be filled, because the game does a math.random() < distributepercent check.

So a distributepercent of 1.1 will fill up everything.

Now, what goes in those points?

That's where the distributeprefabs table goes in. Prefabs are keys, values are pseudo-probabilities.

The game first filters out the prefabs that can't go in the type of ground of the position it wants to fill.

Then it makes a sum of all the pseudo-probabilities. It multiplies this total sum by math.random().

Then it iterates over the filtered prefab table, subtracting the pseudo-probability on the iterator from the last multiplication.

    local total = 0
    for k,v in pairs(items) do
        total = total + v
    end
    if total > 0 then
        local rnd = math.random()*total
        for k,v in pairs(items) do
            rnd = rnd - v
            if rnd <= 0 then
                return k
            end
        end
    end

The higher the value of the prefab, the more chances it has to appear.

The more prefabs with values there are in the table, the less chances a prefab with say, value 1, has to appear.

 

So, if distributepercent is 0.001, a distributeprefab of 0.5 will do most likely nothing.

If distributepercent is 1, a distributeprefab of 0.5 will appear more than the previous case, but also depending on the other distributeprefabs.

@DarkXerothank you very much :)

I thought it would be easier to get all rooms in a list and remove some of them to get the rooms I want... but in fact it is easier to manually make a list with those rooms  :D

If I understood it right, I should be able to add eg. pigtorches to 1%(=Increase) of the avaible space, when I set the value of
room.contents.distributeprefabs = prefabvalue
and
room.contents.distributepercent = room.contents.distributepercent + 0.01
with prefabvalue is:
prefabvalue = ((oldsum * (oldpercent + Increase) / oldpercent) - oldsum

            AddRoomPreInit(roomstring, 
                function(room) 
                    if room.contents then
                        local oldpercent = room.contents.distributepercent or 0
                        local oldsum = 0
                        for distprefab,number in pairs(room.contents.distributeprefabs) do
                            if type(number)=="table" then -- eg: smallmammal = {weight = 0.025, prefabs = {"rabbithole", "molehill"}},
                                for k,v in pairs(number) do
                                    if type(v)=="number" and k=="weight" then
                                        oldsum = oldsum + v
                                    end
                                end
                            elseif type(number)=="number" then
                                oldsum = oldsum + number
                            end
                        end
                        local prefabvalue = round2(((oldsum * (oldpercent + Increase) / oldpercent) - oldsum,8)
                        if not room.contents.distributeprefabs then
                            room.contents.distributeprefabs = {}
                        end
                        room.contents.distributeprefabs[prefab] = (room.contents.distributeprefabs[prefab] and room.contents.distributeprefabs[prefab] + prefabvalue) or prefabvalue
                        room.contents.distributepercent = mymathclamp(oldpercent + Increase,0,1)
                        print("AnimalIncreaser Debug: "..roomstr..": added "..prefab..". oldpercent: "..oldpercent..", oldsum: "..oldsum..", newpercent: "..room.contents.distributepercent..", prefabvalue: "..prefabvalue..", newvalue: "..room.contents.distributeprefabs[prefab])
                    end
                end
            )

I already finished a mod that does this code above for all the rooms I chose.
I tested it with adding 1% pigtorches to these rooms:
BGGrassBurnt, BGGrass, BGSavanna, Plain, BarePlain, BGDeciduous, DeepDeciduous, DeciduousMole, DeciduousClearing, PondyGrass, BGCrappyForest, BGForest, BGDeepForest, BurntForest, CrappyDeepForest, DeepForest, Forest, ForestMole, CrappyForest, BurntClearing, Clearing, BGRocky, Rocky, GenericRockyNoThreat, MolesvilleRocky, BGDirt, BGMarsh, Marsh

But for some reason it is still not good...
At rocky Ground there are only a few torches (1-2 in a screen),
while at forest or grass or savanna ground are areas with 20 torches in one screen (also areas with less, but 20 torches in a screen is just too much, while on all the rocky gound the number is okay)

Can you imagine if I did something wrong?

The goal is of course  mod that lets you increase the number of specific animals and you can choose in which area they should be.
This is an improvement to the loosy game settings... if you set e.g merms in gamesettings to one higher than default, everywhere on every area are hundred of merms, which is just ridiculous :D

Edited by Serpens
15 minutes ago, Serpens said:

Can you imagine if I did something wrong?

Compare the distributepercent of "rocky ground" with the the distributepercent of "forest or grass or savannah".

Also compare the distributeprefabs and their weights.

Then tune accordingly. If you are getting 20 torches on screen, lower the weight for that room.

15 minutes ago, DarkXero said:

Compare the distributepercent of "rocky ground" with the the distributepercent of "forest or grass or savannah".

Also compare the distributeprefabs and their weights.

Then tune accordingly. If you are getting 20 torches on screen, lower the weight for that room.

did you read my code or the calculation?
That calculation already does the tuning automatically and the result should be that it is always 1% of the whole space.
Or is my calculation wrong, because I understood it wrong?

21 minutes ago, Serpens said:

did you read my code or the calculation?

Yes.

If it isn't producing the result you want, then the code is wrong, isn't it?

My conclusion is that I don't want to sit here during lunch with a paper and a pen out, calculating probabilities.

Print the distributepercent value and distributeprefabs table of the rooms that differ, and compare.

Look what the algorithm generates.

 

You can also do

countprefabs = {
	pigtorch = function () return math.random(2) end,
},

to put one or two prefabs in the rooms you like.

Edited by DarkXero
1 hour ago, DarkXero said:

Yes.

If it isn't producing the result you want, then the code is wrong, isn't it?

My conclusion is that I don't want to sit here during lunch with a paper and a pen out, calculating probabilities.

Print the distributepercent value and distributeprefabs table of the rooms that differ, and compare.

Look what the algorithm generates.

 

You can also do


countprefabs = {
	pigtorch = function () return math.random(2) end,
},

to put one or two prefabs in the rooms you like.

No need to hurry :) And thank you so far, I appreciate your help! :)

In the code is already a print of all relevant values. And it does exactly what I want it to do. So the code is correct.

Spoiler

[00:01:46]: Applying mod to room 'PondyGrass'    
[00:01:46]: AnimalIncreaser Debug: PondyGrass: added pigtorch. oldpercent: 0.2, oldsum: 1.58, newpercent: 0.21, prefabvalue: 0.079, newvalue: 0.079    
[00:01:46]: Applying mod to room 'Forest'    
[00:01:46]: AnimalIncreaser Debug: Forest: added pigtorch. oldpercent: 0.3, oldsum: 8.07, newpercent: 0.31, prefabvalue: 0.269, newvalue: 0.269    
[00:01:46]: Applying mod to room 'Forest'    
[00:01:46]: AnimalIncreaser Debug: Forest: added pigtorch. oldpercent: 0.3, oldsum: 8.07, newpercent: 0.31, prefabvalue: 0.269, newvalue: 0.269    
[00:01:46]: Applying mod to room 'Forest'    
[00:01:46]: AnimalIncreaser Debug: Forest: added pigtorch. oldpercent: 0.3, oldsum: 8.07, newpercent: 0.31, prefabvalue: 0.269, newvalue: 0.269    
[00:01:46]: Applying mod to room 'Rocky'    
[00:01:46]: AnimalIncreaser Debug: Rocky: added pigtorch. oldpercent: 0.1, oldsum: 11.412, newpercent: 0.11, prefabvalue: 1.1412, newvalue: 1.1412    
[00:01:46]: Applying mod to room 'Rocky'    
[00:01:46]: AnimalIncreaser Debug: Rocky: added pigtorch. oldpercent: 0.1, oldsum: 11.412, newpercent: 0.11, prefabvalue: 1.1412, newvalue: 1.1412    
[00:01:46]: Applying mod to room 'Clearing'    
[00:01:46]: AnimalIncreaser Debug: Clearing: added pigtorch. oldpercent: 0.1, oldsum: 4.505, newpercent: 0.11, prefabvalue: 0.4505, newvalue: 0.4505    
[00:01:46]: Applying mod to room 'Clearing'    
[00:01:46]: AnimalIncreaser Debug: Clearing: added pigtorch. oldpercent: 0.1, oldsum: 4.505, newpercent: 0.11, prefabvalue: 0.4505, newvalue: 0.4505    
[00:01:46]: Applying mod to room 'Plain'    
[00:01:46]: AnimalIncreaser Debug: Plain: added pigtorch. oldpercent: 0.2, oldsum: 0.955, newpercent: 0.21, prefabvalue: 0.04775, newvalue: 0.04775    
[00:01:46]: Applying mod to room 'Plain'    
[00:01:46]: AnimalIncreaser Debug: Plain: added pigtorch. oldpercent: 0.2, oldsum: 0.955, newpercent: 0.21, prefabvalue: 0.04775, newvalue: 0.04775    
[00:01:46]: Applying mod to room 'Plain'    
[00:01:46]: AnimalIncreaser Debug: Plain: added pigtorch. oldpercent: 0.2, oldsum: 0.955, newpercent: 0.21, prefabvalue: 0.04775, newvalue: 0.04775    
[00:01:46]: Applying mod to room 'Plain'    
[00:01:46]: AnimalIncreaser Debug: Plain: added pigtorch. oldpercent: 0.2, oldsum: 0.955, newpercent: 0.21, prefabvalue: 0.04775, newvalue: 0.04775    
[00:01:46]: Applying mod to room 'BGGrass'    
[00:01:46]: AnimalIncreaser Debug: BGGrass: added pigtorch. oldpercent: 0.275, oldsum: 1.304, newpercent: 0.285, prefabvalue: 0.04741818, newvalue: 0.04741818    
[00:01:46]: Applying mod to room 'BGGrass'    
[00:01:46]: AnimalIncreaser Debug: BGGrass: added pigtorch. oldpercent: 0.275, oldsum: 1.304, newpercent: 0.285, prefabvalue: 0.04741818, newvalue: 0.04741818    
[00:01:46]: Applying mod to room 'BGRocky'    
[00:01:46]: AnimalIncreaser Debug: BGRocky: added pigtorch. oldpercent: 0.1, oldsum: 5.208, newpercent: 0.11, prefabvalue: 0.5208, newvalue: 0.5208    
[00:01:46]: Applying mod to room 'BGRocky'    
[00:01:46]: AnimalIncreaser Debug: BGRocky: added pigtorch. oldpercent: 0.1, oldsum: 5.208, newpercent: 0.11, prefabvalue: 0.5208, newvalue: 0.5208    
[00:01:46]: Applying mod to room 'Clearing'    
[00:01:46]: AnimalIncreaser Debug: Clearing: added pigtorch. oldpercent: 0.1, oldsum: 4.505, newpercent: 0.11, prefabvalue: 0.4505, newvalue: 0.4505    
[00:01:46]: Applying mod to room 'Clearing'    
[00:01:46]: AnimalIncreaser Debug: Clearing: added pigtorch. oldpercent: 0.1, oldsum: 4.505, newpercent: 0.11, prefabvalue: 0.4505, newvalue: 0.4505    
[00:01:46]: Applying mod to room 'Forest'    
[00:01:46]: AnimalIncreaser Debug: Forest: added pigtorch. oldpercent: 0.3, oldsum: 8.07, newpercent: 0.31, prefabvalue: 0.269, newvalue: 0.269    
[00:01:46]: Applying mod to room 'Clearing'    
[00:01:46]: AnimalIncreaser Debug: Clearing: added pigtorch. oldpercent: 0.1, oldsum: 4.505, newpercent: 0.11, prefabvalue: 0.4505, newvalue: 0.4505    
[00:01:46]: Applying mod to room 'Rocky'    
[00:01:46]: AnimalIncreaser Debug: Rocky: added pigtorch. oldpercent: 0.1, oldsum: 11.412, newpercent: 0.11, prefabvalue: 1.1412, newvalue: 1.1412    
[00:01:46]: Applying mod to room 'Rocky'    
[00:01:46]: AnimalIncreaser Debug: Rocky: added pigtorch. oldpercent: 0.1, oldsum: 11.412, newpercent: 0.11, prefabvalue: 1.1412, newvalue: 1.1412    
[00:01:46]: Applying mod to room 'Rocky'    
[00:01:46]: AnimalIncreaser Debug: Rocky: added pigtorch. oldpercent: 0.1, oldsum: 11.412, newpercent: 0.11, prefabvalue: 1.1412, newvalue: 1.1412    
[00:01:46]: Applying mod to room 'Forest'    
[00:01:46]: AnimalIncreaser Debug: Forest: added pigtorch. oldpercent: 0.3, oldsum: 8.07, newpercent: 0.31, prefabvalue: 0.269, newvalue: 0.269    
[00:01:46]: Applying mod to room 'Forest'    
[00:01:46]: AnimalIncreaser Debug: Forest: added pigtorch. oldpercent: 0.3, oldsum: 8.07, newpercent: 0.31, prefabvalue: 0.269, newvalue: 0.269    
[00:01:46]: Applying mod to room 'DeepForest'    
[00:01:46]: AnimalIncreaser Debug: DeepForest: added pigtorch. oldpercent: 0.8, oldsum: 7.5, newpercent: 0.81, prefabvalue: 0.09375, newvalue: 0.09375    
[00:01:46]: Applying mod to room 'DeepForest'    
[00:01:46]: AnimalIncreaser Debug: DeepForest: added pigtorch. oldpercent: 0.8, oldsum: 7.5, newpercent: 0.81, prefabvalue: 0.09375, newvalue: 0.09375    
[00:01:46]: Applying mod to room 'Forest'    
[00:01:46]: AnimalIncreaser Debug: Forest: added pigtorch. oldpercent: 0.3, oldsum: 8.07, newpercent: 0.31, prefabvalue: 0.269, newvalue: 0.269    
[00:01:46]: Applying mod to room 'Clearing'    
[00:01:46]: AnimalIncreaser Debug: Clearing: added pigtorch. oldpercent: 0.1, oldsum: 4.505, newpercent: 0.11, prefabvalue: 0.4505, newvalue: 0.4505    
[00:01:46]: Applying mod to room 'DeepForest'    
[00:01:46]: AnimalIncreaser Debug: DeepForest: added pigtorch. oldpercent: 0.8, oldsum: 7.5, newpercent: 0.81, prefabvalue: 0.09375, newvalue: 0.09375    
[00:01:46]: Applying mod to room 'Forest'    
[00:01:46]: AnimalIncreaser Debug: Forest: added pigtorch. oldpercent: 0.3, oldsum: 8.07, newpercent: 0.31, prefabvalue: 0.269, newvalue: 0.269    
[00:01:46]: Applying mod to room 'ForestMole'    
[00:01:46]: AnimalIncreaser Debug: ForestMole: added pigtorch. oldpercent: 0.3, oldsum: 8.37, newpercent: 0.31, prefabvalue: 0.279, newvalue: 0.279    
[00:01:46]: Applying mod to room 'ForestMole'    
[00:01:46]: AnimalIncreaser Debug: ForestMole: added pigtorch. oldpercent: 0.3, oldsum: 8.37, newpercent: 0.31, prefabvalue: 0.279, newvalue: 0.279    
[00:01:46]: Applying mod to room 'Clearing'    
[00:01:46]: AnimalIncreaser Debug: Clearing: added pigtorch. oldpercent: 0.1, oldsum: 4.505, newpercent: 0.11, prefabvalue: 0.4505, newvalue: 0.4505    
[00:01:46]: Applying mod to room 'CrappyDeepForest'    
[00:01:46]: AnimalIncreaser Debug: CrappyDeepForest: added pigtorch. oldpercent: 0.8, oldsum: 6.93, newpercent: 0.81, prefabvalue: 0.086625, newvalue: 0.086625    
[00:01:46]: Applying mod to room 'CrappyForest'    
[00:01:46]: AnimalIncreaser Debug: CrappyForest: added pigtorch. oldpercent: 0.3, oldsum: 8.12, newpercent: 0.31, prefabvalue: 0.27066667, newvalue: 0.27066667    
[00:01:46]: Applying mod to room 'CrappyForest'    
[00:01:46]: AnimalIncreaser Debug: CrappyForest: added pigtorch. oldpercent: 0.3, oldsum: 8.12, newpercent: 0.31, prefabvalue: 0.27066667, newvalue: 0.27066667    
[00:01:46]: Applying mod to room 'CrappyForest'    
[00:01:46]: AnimalIncreaser Debug: CrappyForest: added pigtorch. oldpercent: 0.3, oldsum: 8.12, newpercent: 0.31, prefabvalue: 0.27066667, newvalue: 0.27066667    
[00:01:46]: AnimalIncreaser Debug: BGForest: added pigtorch. oldpercent: 0.6, oldsum: 2.036, newpercent: 0.61, prefabvalue: 0.03393333, newvalue: 0.03393333    
[00:01:46]: Applying mod to room 'BGRocky'    
[00:01:46]: AnimalIncreaser Debug: BGRocky: added pigtorch. oldpercent: 0.1, oldsum: 5.208, newpercent: 0.11, prefabvalue: 0.5208, newvalue: 0.5208    
[00:01:46]: Applying mod to room 'BGForest'    
[00:01:46]: AnimalIncreaser Debug: BGForest: added pigtorch. oldpercent: 0.6, oldsum: 2.036, newpercent: 0.61, prefabvalue: 0.03393333, newvalue: 0.03393333   


And from my understanding also the calculation is correct.... but I will calculate it again.. maybe there is a mistake I did not see...
It makes sure that the intial amount of other things stays the same (by also increasing the percent value), and adds the pigtorches.


So the only possibilties are:
- I understood it wrong.
- there is something additional that I have to take into account

The countprefabs does not take the size of the room into account, or does it?
One end result I would like to achieve is e.g one pigtorch on a screen on every ground (room).

 

edit:
Is it possible to print the room my character is standing ingame?
 

Edited by Serpens

Okay, to test it more, I set the
distributepercent
from All the grass rooms I use to: 0.875 + 0.01   ("BGGrassBurnt","BGGrass")
And the Rocky stuff is still: 0.1 + 0.01    ("BGRocky","Rocky","GenericRockyNoThreat","MolesvilleRocky")

So at grass will be alot of stuff, but still should be 1% of the space pigtorches.
This is the result:
http://steamcommunity.com/profiles/76561198102311542/screenshots

Spoiler

[00:00:46]: Applying mod to room 'Rocky'    
[00:00:46]: AnimalIncreaser Debug: Rocky: added pigtorch. oldpercent: 0.1, oldsum: 11.412, newpercent: 0.11, prefabvalue: 1.1412, newvalue: 1.1412    
[00:00:46]: Applying mod to room 'Rocky'    
[00:00:46]: AnimalIncreaser Debug: Rocky: added pigtorch. oldpercent: 0.1, oldsum: 11.412, newpercent: 0.11, prefabvalue: 1.1412, newvalue: 1.1412    
[00:00:46]: Applying mod to room 'Rocky'    
[00:00:46]: AnimalIncreaser Debug: Rocky: added pigtorch. oldpercent: 0.1, oldsum: 11.412, newpercent: 0.11, prefabvalue: 1.1412, newvalue: 1.1412    
[00:00:46]: Applying mod to room 'MolesvilleRocky'    
[00:00:46]: AnimalIncreaser Debug: MolesvilleRocky: added pigtorch. oldpercent: 0.1, oldsum: 7.5, newpercent: 0.11, prefabvalue: 0.75, newvalue: 0.75    
[00:00:46]: Applying mod to room 'GenericRockyNoThreat'    
[00:00:46]: AnimalIncreaser Debug: GenericRockyNoThreat: added pigtorch. oldpercent: 0.1, oldsum: 13.056, newpercent: 0.11, prefabvalue: 1.3056, newvalue: 1.3056    
[00:00:46]: Applying mod to room 'GenericRockyNoThreat'    
[00:00:46]: AnimalIncreaser Debug: GenericRockyNoThreat: added pigtorch. oldpercent: 0.1, oldsum: 13.056, newpercent: 0.11, prefabvalue: 1.3056, newvalue: 1.3056    
[00:00:46]: Applying mod to room 'GenericRockyNoThreat'    
[00:00:46]: AnimalIncreaser Debug: GenericRockyNoThreat: added pigtorch. oldpercent: 0.1, oldsum: 13.056, newpercent: 0.11, prefabvalue: 1.3056, newvalue: 1.3056    
[00:00:46]: LinkNodesByKeys    
[00:00:46]: Finding valid start task...    
[00:00:46]:    ...picked     Make a pick    
[00:00:46]: Has start node    Clearing    
[00:00:46]: Applying mod to room 'BGGrass'    
[00:00:46]: AnimalIncreaser Debug: BGGrass: added pigtorch. oldpercent: 0.875, oldsum: 1.304, newpercent: 0.885, prefabvalue: 0.01490286, newvalue: 0.01490286    
[00:00:46]: Applying mod to room 'BGGrass'    
[00:00:46]: AnimalIncreaser Debug: BGGrass: added pigtorch. oldpercent: 0.875, oldsum: 1.304, newpercent: 0.885, prefabvalue: 0.01490286, newvalue: 0.01490286    
[00:00:46]: Applying mod to room 'BGGrass'    
[00:00:46]: AnimalIncreaser Debug: BGGrass: added pigtorch. oldpercent: 0.875, oldsum: 1.304, newpercent: 0.885, prefabvalue: 0.01490286, newvalue: 0.01490286    
[00:00:46]: Applying mod to room 'BGRocky'    
[00:00:46]: AnimalIncreaser Debug: BGRocky: added pigtorch. oldpercent: 0.1, oldsum: 5.208, newpercent: 0.11, prefabvalue: 0.5208, newvalue: 0.5208    
[00:00:46]: Applying mod to room 'BGGrass'    
[00:00:46]: AnimalIncreaser Debug: BGGrass: added pigtorch. oldpercent: 0.875, oldsum: 1.304, newpercent: 0.885, prefabvalue: 0.01490286, newvalue: 0.01490286    

 

- So at least at one of the grass areas, the total number of pigtorches really could be 1% of the grass space... but it is just very poorly distributed... I noticed that also at forest. It seems they are more often near Roads?!
- At the decidious tree grass... this can't be 1% of the total space...
- And at rocky, it is absolutely okay.

Looking at those screenshots... I think the calculation is correct.
But the problem is, that the pigtorches have a wuite high chance to spawn near roads.
And because on rocky the percent change is quite low, it does not stick out.

So how to change this strange distribution?!

Edited by Serpens
39 minutes ago, Serpens said:

It makes sure that the intial amount of other things stays the same (by also increasing the percent value), and adds the pigtorches.


So the only possibilties are:
- I understood it wrong.
- there is something additional that I have to take into account

What two rooms should I compare?

Also, the pairs iterator is arbitrary. The table may be parsed in any order.

Honestly, I would edit all cases separately and avoid the headaches.

41 minutes ago, Serpens said:

The countprefabs does not take the size of the room into account, or does it?

No.

41 minutes ago, Serpens said:

One end result I would like to achieve is e.g one pigtorch on a screen on every ground (room).

If this is your end result then you may as well pick a random location, and move all over the map.

Like putting this so that it loads once on world generation.

local invalid_tile = GLOBAL.GROUND.INVALID
local impassable_tile = GLOBAL.GROUND.IMPASSABLE
local map = GLOBAL.TheWorld.Map
local SpawnPrefab = GLOBAL.SpawnPrefab

for i = -10000, 10000, 50 do
	for j = -10000, 10000, 50 do
		local tile = map:GetTileAtPoint(i, 0, j)
		if tile ~= invalid_tile and tile ~= impassable_tile then
			local pigtorch = SpawnPrefab("pigtorch")
			pigtorch.Transform:SetPosition(i, 0, j)
		end
	end
end
44 minutes ago, Serpens said:

Is it possible to print the room my character is standing ingame?

c_select(ThePlayer)

Press backspace to display debug info.

Look for where it says "areaaware".

You will see task, room, if it's default/background, and the tags of the room.

13 minutes ago, Serpens said:

- At the decidious tree grass... this can't be 1% of the total space...

You increase by 1% the total space of everything.

It just happened, that instead of putting trees, or saplings, or grass in the area, it put pig torches.

So you should lower the weight of the pig torches.

Quote

 If this is your end result then you may as well pick a random location, and move all over the map.
Like putting this so that it loads once on world generation.

Of course a bit more randomness would be good.
And I thought using the rooms would be good also to avoid placing pigtorches at specific rooms, like SpiderCity and so on.
So I would need a way to get the room for every of these positions. I can imagine that would be hard work for PC.
 

Quote

c_select(ThePlayer)
Press backspace to display debug info.
Look for where it says "areaaware".
You will see task, room, if it's default/background, and the tags of the room.

Thanks :)

Quote

You increase by 1% the total space of everything.
It just happened, that instead of putting trees, or saplings, or grass in the area, it put pig torches.
So you should lower the weight of the pig torches.

But I changed it this way, that the total amount should be 1%.
I know this is random, but if 1% is the goal, it has chance of 0.00000000000000000000000000001 that 80% of the space has pigtorches, like it is in this screenshot :D
 

It don't see the point of lowering the weight, cause what to achieve with this?
I mean there is a logic behind this gamesystem. The logic you posted in the second post.
And I used this logic to make my calculation, which is correct (at least I calculated it a hundred times now, and don't find any mistake).

So if my calculation has still a wrong result, the logic we assume has to be wrong.
And if our logic is wrong, it makes no sense to lower the weight, since we don't know the effects of it, since we don't have a logic.

Of course I could just set a new weight, start the game, look at various places... set another weight and repeat...
After half an hour I may have an acceptable value.
But I would have to repeat this for ALL the other rooms too. This makes the headaches! :D
That's why we really need one calculation formula, to calculate all of this automatically.


To visualize my calculation:
There are 1000 points in a room, where something could spawn.
Percent is 0.1 ,so at 100 places sometheing will be placed,
and I want 1% of these 1000 points to be pigtorches -> 10 pigtorches.
So to make 10 of those 100 things pigtorches, the distributeprefabs weight of pitorches must be 10/90 from the oldsum of all other weights.
Then we would have 10 pigtorches, and 90 other things.

Now we extend this:
We now want the number of other things unchanged. So we want 100 things and 10 pigtorches as a result.
Thats why we increase the percent value by 0.01 to 0.11.
Now at 110 positions from the 1000 total position something will be placed.
To achieve 10 pigtorches, the distributeprefabs weight from pigtorches has to be 10/100 from the oldsum.
And this is exactly what my calculation does:
[00:00:46]: AnimalIncreaser Debug: Rocky: added pigtorch. oldpercent: 0.1, oldsum: 11.412, newpercent: 0.11, prefabvalue: 1.1412, newvalue: 1.1412    

Now we compare it with higher percent value:
We have again 1000 positions.
Percent is now 0.875, which means at 875 of these positions something will be placed.
Again we want 1% of 1000 to be pigtorches, and 875 other things.
So we increase the percent value to 0.885 -> 885 postiions with something.
The distributeprefabs weight from pigtorches now has to be 10/875 from the oldsum.
[00:00:46]: AnimalIncreaser Debug: BGGrass: added pigtorch. oldpercent: 0.875, oldsum: 1.304, newpercent: 0.885, prefabvalue: 0.01490286, newvalue: 0.01490286    


I tested the result ingame now with a percent value of 0.1+0.01 for Grass.
And now the result does look the same like for Rocky.
So it indeed depends on the percent value... but it should not.

I absolutely have no clue, why the result looks so differnt. I can't be different, if the logic from your second post is right.
Is there a script where I can look up this logic? @DarkXero

edit:
ok, found the script where to look up the logic. forest_map.lua ... I will study it now...

Edited by Serpens

Okay... looking at the code from forest_map.lua I think I found the problem:


The function that does the distribution checks terrainfilters.
And nearly everything can't be placed near roads.
But pigtorches have no such filter.

So every position near a road, has only pigtorch as a valid choice!

That is the reason, why there are so many torches near roads ;) So I will add a filter for pigtorches

2 hours ago, Serpens said:

That is the reason, why there are so many torches near roads

I thought rocks and trees could be near roads, but it seems that's not the case.

So, that was pretty much it and you nailed it.

Because when the game makes a list of prefabs to pick from, if only one choice is valid, then the weight doesn't matter.

49 minutes ago, Serpens said:

It does not work anymore. Also with GLOBAL in any combinatin seems not to work... and also GetPlayer() instead of ThePlayer does not work ...

GetPlayer() returns ThePlayer (and also pops a message saying that GetPlayer() is deprecated).

Also, ThePlayer is nil on the server (unless you are a caveless host), so doing "Remote: c_select(ThePlayer)" does nothing.

Doing any, for example, "Remote: c_select(c_find("grass"))" will make the server select that entity as a debug entity.

You don't select it. The server does. So pressing backspace does nothing.

You want to select it yourself. Press the Ctrl key to remove the "Remote:" and run the command locally.

Fortunately for you, the areaaware component is both a server and client component.

So you will have access to it and its debugstring.

Again, running "c_select(ThePlayer)" will do the trick, but remove the "Remote:" by pressing Ctrl.

ThePlayer in a client simulation refers to the client's player prefab.

3 hours ago, Serpens said:

it should work as a server_only mod, right?

It's not a matter of "modmain has code", but about what the code does.

In your case, you edit world generation, clients don't care about this, so yes, it is server only.

If, for example, you added new ground tiles to the game in modworldgenmain, then it would be a client required mod.

13 minutes ago, DarkXero said:

It's not a matter of "modmain has code", but about what the code does.

In your case, you edit world generation, clients don't care about this, so yes, it is server only.

If, for example, you added new ground tiles to the game in modworldgenmain, then it would be a client required mod.

Although if new ground tiles are only needed for generating the world?

So if I add new setpieces (with already existing things) for world generation, it has to be all client reqiure mod?
Or is it only a all_client mod, when I make setpieces with new things ? In my case I would add a new scenario for chest-traps. I guess if I add this scenraio, it has to be all_client, right?

39 minutes ago, Serpens said:

Although if new ground tiles are only needed for generating the world?

My point is that if the server adds GROUND.NEWGROUNDHELLOWORLD to the tileset, then clients won't know about it if it stays server only.

40 minutes ago, Serpens said:

So if I add new setpieces (with already existing things) for world generation, it has to be all client reqiure mod?
Or is it only a all_client mod, when I make setpieces with new things ? In my case I would add a new scenario for chest-traps. I guess if I add this scenraio, it has to be all_client, right?

Set pieces are prefabs dumped into the world. Clients don't care, as long as they have the prefabs the set piece uses.

Scenarios are server side functions.

So the answers are "no", "no (unless the new things are new prefabs)", and "no".

 

If the game doesn't break when the mod is server only, and the mod behaves as intended, then it's server only.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...