Careful Driver


Encourages players to be careful drivers via negative reinforcement.

Content
2 years ago
1.1
119
Transportation

i Some optimizations

1 year, 6 months ago
(updated 1 year, 6 months ago)

Hi! Checking your code for potential compatibility issues with Autodrive, I've noticed two things you could optimize:

(1) In scripts/driven-car.lua, lines 288ff., you have this:

    -- See if it stopped from hitting a cliff in its travelling direction.
    if global.drivenCar.settings.cliffCollision then
        -- CODE NOTE: Factorio doesn't support us passing in an orientation as part of a BoundingBox to any of its API functions, so we have to do it as a square area and then manually check any results for diagonal collisions.

You may have missed that, but with Factorio 1.1.82, it is indeed possible to use BoundingBox with orientation (see here). I use that to search the area before or behind a vehicle instead of approximating an area by searching multiple position. You probably should keep the old code for backwards compatibility until Factorio >=1.1.82 hits stable.

(2) I've also tried to detect collisions of vehicles with cliffs. The approach I've used so far is similar to yours (check for vehicle.position not changing over n ticks while vehicle.speed ~= 0). However, since Factorio 1.1.74 car prototypes have the property immune_to_cliff_impacts, which is true by default. If you set this to false, cars will take damage on hitting a cliff, so on_entity_damaged should be raised. I'm still undecided whether I should use this approach to detect cliff collisions because it is vulnerable to other mods (that run after mine) resetting the flag.

1 year, 3 months ago

Thanks for flagging both of these back then.

1: yea looking at release dates Factorio 1.1.82 came out after I started working on this mod. That limitation seems familiar so likely I either raised it as an issue with the devs, or found someone already had back in the day.

2: Yea I saw that in the game, but by the time it was released I had added the future hope of allowing the player to drive off/down a cliff, and so no longer had a need for it. If I don't allow driving off/down cliffs it might be an idea to use the flag as simpler and less UPS, but as you mention it is vulnerable to other mods reacting to the event first and reaching a state when my reaction to it is irrelevant.