Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeploySpacingRadius doesn't work #23

Closed
cyisfor opened this issue Mar 5, 2018 · 7 comments
Closed

DeploySpacingRadius doesn't work #23

cyisfor opened this issue Mar 5, 2018 · 7 comments

Comments

@cyisfor
Copy link

cyisfor commented Mar 5, 2018

Sadly, it appears that Klei seriously messed with the plant placement radius. When stuff like grass and bushes are placed, the space they take up is not a square, or a perfect circle, or at least it's not centered on the spot the object is placed. When I clicked the book to plant a grid, all the slots showed up as green, but some started to turn red as plants were planted. It seemed to follow a pattern, but it didn't seem to be regular. The unplantable spots even varied depending on my camera angle. The pattern was also different depending on which plant was being planted.

I could post grids of what turned red when what was planted, but I think it might be combinations of plants that make nearby spots unplantable, and the one that turned it unplantable was just the last straw. Sometimes when I dug up the plants that successfully planted, the spot they occupied was unplantable, so even the order you plant them in matters!

I don't even want to think how frustrating this would be for someone trying to place them by hand.

Fortunately, this complex, challenging problem can be easily solved by ignoring it and setting DEPLOYSPACING_EXTRA to 0.3. It plants the rows lined up then, with no unplantable gaps, at any angle, for any plant that I could see. I tried 0.1 and 0.2 but only 0.3 was free of error. If that's too much of a gap... then I dunno what the solution is.

@taichunmin
Copy link
Collaborator

I think there are two possible reasons for this error:

  1. My Code has bug. (Maybe you can help me to check that?)
  2. The precision problem of float point

Because I want to make plant position always on players top, no matter what angle. So I write some code to calculate the first (x,y) and then add offset. Maybe there are some bug. I am not sure.

@cyisfor
Copy link
Author

cyisfor commented Mar 11, 2018

I'm closer to finding the problem, but still pretty stumped. I enabled Geometric Placement, and Camera Tweaks so I could get a top-down view, and... it might partially be Geometric Placement's choice of grid density in particular, but...


Plants take up different amounts of space depending on where you plant them.

It's some sort of alignment issue, I'm sure of it, because no matter whether Geometric Placement was set to rotate 45 degrees or not, every item planted took up the same area. But when I tried disabling Geometric Placement and manually placing some grass above that, without a grid, the area each tuft took up varied quite a bit. Maybe it has to be aligned every 10 pixels, or every 20 pixels, or something. (Every 10 pixels according to what reference point?) This mod does already align the things it places on a grid, so the grid just has to be adjusted so it matches up with the game's internal alignment requirements. Then, I bet you could set DEPLOYSPACING_EXTRA to 0!

@cyisfor
Copy link
Author

cyisfor commented Mar 11, 2018

Also checked components/map.lua, under IsDeployPointClear... It calls TheSim:FindEntities which I'm not sure uses a circular distance, or a square distance... and of course is behind the closed source wall. There's a minimum spacing (DeploySpacingRadius), and also deploy_extra_spacing, though that's only used for a few structures like lava pools. If that's not confusing enough, I think then it checks the square distance from each of those entities, to see if any are too close. So... inside a maximum circle, but then checks the square distance within. So pretty much just the square distance to nearby structures.

But... then... why would the space a thing took up be a different shape at different alignments? Wouldn't it just always be a... square? Maybe I should tweak Geometric Placement to have a ridiculously fine grid, to see if a square shape emerges from that, which doesn't look square from its default grid.

@cyisfor
Copy link
Author

cyisfor commented Mar 11, 2018

this

Nope, still confused... changing the grid gave me this which indicates that the area something takes up really is a perfect circle, centered in this case on the bottom of the grass tuft, in the exact middle of it horizontally.

Okay, so util.lua has the "distsq" function which isn't the square distance. It's the square of the distance. I was thinking like the "Manhattan distance" but actually the sq just means they're skipping calculating the square root, not that it's square shaped.. So it does measure the real, circular distance from the object. Hmm... is the center of that circle offset from the exact location of the object?

@cyisfor
Copy link
Author

cyisfor commented Mar 12, 2018

And now it... works perfectly fine. I can't reproduce the bug anymore, and everything plants perfectly close together at the original DEPLOYSPACING_EXTRA = 0.1. I swear sometimes bugs I find disappear just because I look at the code and logically prove that the bugs couldn't have ever existed. Maybe I had a mod, or... something? No other placement mod besides this and Geometric though. Oh well, sorry for making a fuss.

@cyisfor cyisfor closed this as completed Mar 12, 2018
@taichunmin
Copy link
Collaborator

@cyisfor I has updated a newer version which can alter plantable margin in settings.
Please check http://steamcommunity.com/sharedfiles/filedetails/?id=950413860

@cyisfor
Copy link
Author

cyisfor commented Mar 31, 2018

Thanks taichunmin! I also have since learned that the only mod that does mess up this mod is Geometric Placement, and it just so happens that's what I had trouble with! Your mod works super good, once I set Geometric Placement to be off by default, unless the modifier is pressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants