Automatically placing construction sites



  • I have a template which I use in every base. I choose the centre-position of the template once and store it in memory. It's an expensive operation (10s-100s of CPU).

    Periodically I iterate over the template and see if any construction sites need to be created. This is moderately expensive (1s-10s of CPU) but I only do this every X ticks so it averages out to quite a low cpu cost per tick.



  • I'm similar to wtfrank.

    Each room has a centre position which is calculated once and cached. All structures are offset from that position. For me the cost to calculate this is not so expensive because of how simple(good) and inflexible(bad) the design is.

    Normally I check a room only when it has gone up/down in RCL or the cache key(owned structure count) is invalid.

    In practice, my architecture (name of the operation in charge of core structures) CPU costs are negligible, but my design is really basic.



  • My code calculates where it places it buildins once (cost easily >400 CPU), but saves this as template. Every xxx ticks i recalculate which buildings need to be build (are missing) which then is saved, and then, as long as something need to be build, they are placed if there are not too many contructions sites already (i think its 5, and 10 for roads), mostly extension structures first.



  • I track the type and xy of all of my base structures (well not containers).

    I only run the upkeep if there are less than 3 construction sites. The upkeep checks the structure and site count. If they are different than expected last tick I recalc. The recalc iterates through all the structure types my room has memorized. If the number of actual structures is less than the RCL permits and the number of actual structures is less than the number of tracked structures I iterate over all of the tracked structures and try to create a new constructions site as each position. As soon as one returns OK I exit the structure upkeep.

    I do this every tick. In the steady state this consumes minimal CPU. It helps that my code is already tracking the number of structs and sites from last tick for my structure cache.

    This technique allows me to rebuild the instant I need to. I have a slightly different flow when there are a hostiles in the room. (Protip: don't build a rampart over the top of an attacking a hostile).



  • @deft-code said in Automatically placing construction sites:

    (Protip: don't build a rampart over the top of an attacking a hostile).

    I'm intrigued. What happens when you build a rampart on top of a hostile creep?


  • Dev Team

    @orlet The rampart will protect him against you.



  • Can you build a rampart on top of someone elses creep? I thought having another players creep on your construction site removes it


  • Dev Team

    @obamallama stepping over construction site removes it, but it you place construction site over hostile creep it persists



  • @o4kapuk wow, thanks! I had no idea 🙂



  • My code places a container next to my initial spawn, and then flowers out based on that. It creates a grid of center locations of these flowers, checks to make sure the center locations aren't too close to my walls, and then picks the closest one to the center and builds away.

    The storage and labs I set a flag in the room and it builds off a template from the flag.