spider-vehicle unselectable if it is too high

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1410
Joined: Sun Oct 14, 2018 8:13 am
Contact:

spider-vehicle unselectable if it is too high

Post by Pi-C »

I've added the companion from Klonan's "Companion Drones" to the prototypes I scale with my mod. The companion is based on a spider-vehicle prototype, which has the property "height" which "affects the shooting height and the drawing of the graphics and lights". I've noticed that the drone couldn't be selected when it was scaled by a factor of 5.

Narrowing it down, I found that it would be selectable as expected for a factor <3, that it would be selectable when the cursor hovered exactly on the yellow line of the selection box for a factor in the range 3.00 … 3.03, and that it would be unselectable for a factor >= 3.04 (original height is 2, so the problems start if height == 6).

Why would the height of the spider-vehicle affect whether its selection_box is active? Does something overlap the selection_box, so that it becomes inaccessible?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Pi-C
Smart Inserter
Smart Inserter
Posts: 1410
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: spider-vehicle unselectable if it is too high

Post by Pi-C »

There's nothing better than a live example, so I'll attach my WIP version of the mod + a saved game that you can sync with. There is some heavy logging going on during the data stage, so you can follow what's going on.

The drones in the saved game have been scaled by a factor of 5 -- with the height property, so the drones are unselectable. You can change the scale factor via a startup setting (requires restart). For comparison, you can comment out lines 525-530 in scripts.scale_bots:

Code: Select all

    -- Adjust prototypes of fake bots
    if robot.type == "spider-vehicle" and robot.height then
SR.show("robot.height", robot.height)
      robot.height = robot.height * scale
SR.show("robot.height after scaling", robot.height)
    end
Attachments
SmallRobots_1.1.3.zip
(57.94 KiB) Downloaded 5 times
scale_test.zip
(1.53 MiB) Downloaded 5 times
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 1908
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: spider-vehicle unselectable if it is too high

Post by boskid »

This is related to how entity selection in 1.1.x is implemented. Entity selection is searching for entities using entity searches which are based on collision boxes. Area with entities is based on the cursor position, around which a box with radius of 2 tiles is expanded and it is further expanded to cover full advanced tiles (2x2). If the entity to be selected is not seen in any of the advanced tiles in the above mentioned area, it will fail the selection condition by simply not being found by the entity search.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1410
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: spider-vehicle unselectable if it is too high

Post by Pi-C »

Thank you for the explanation! I guess the easiest way to work around this problem is to reduce the maximum scale factor from 5.0 to 2.5…3.0. I'm not even sure anybody is really using a scale factor >1 -- and if anybody really were to scale the bots up to 500% of their original size, they'd probably do that just out of curiosity, not to play a complete game with that.

Downscaling the bots (so they correspond to the size of the character when my other scaling mod is used) actually has a practical reason (smaller characters/bots don't look as much out of place besides vehicles or buildings), but upscaling is just a gimmick (upscaled characters look more clumsy because the graphics aren't optimized for huge blowups and the characters seem to move slower; besides, they obstruct the view of the things you want to build).
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

PFQNiet
Filter Inserter
Filter Inserter
Posts: 277
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: spider-vehicle unselectable if it is too high

Post by PFQNiet »

Forgive me if this is a daft question, but why is the search for selection boxes implemented using collision boxes? I'm guessing code reuse, since collision boxes are used in so many more places?

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 1908
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: spider-vehicle unselectable if it is too high

Post by boskid »

PFQNiet wrote:
Thu Jan 26, 2023 10:54 am
..., but why is the search for selection boxes implemented using collision boxes?
Entities are registering on the surface based on their collision boxes because entity collisions is the most common case where entity searches are required. Selection is less common use case so if possible we try to reuse the existing entity search logic without inventing new ones. Entity rendering is also reusing the entity searches, EntityRenderer is just an entity search and if an entity is rendering stuff way outside of the collision box it may not be found by the entity renderer and as such not be rendered. In order to account for entities that are drawing way outside of their collision box there is a utility constant named `entity_renderer_search_box_limits` which is used to expand the screen area a little to also find other entities that have collision box outside of the screen but could still have something rendered on screen. For entity selection for now there is this limit of 2 tiles + margin due to advanced tiles and there are no ways to easily solve this without a modding interface requests. Due to various refactorings, this case will be correctly handled in 1.2 as there is an extra step that goes through all entity prototypes and checks how much a selection box is being outside of the collision box and that value is then used to expand the entity searches for selection purposes.

Post Reply

Return to “Modding discussion”