Implementation of a "Construction Unit" for RTS mod

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
kyranzor
Filter Inserter
Filter Inserter
Posts: 499
Joined: Fri Oct 31, 2014 4:52 pm
Contact:

Implementation of a "Construction Unit" for RTS mod

Post by kyranzor »

I am planning to implement a mobile construction unit (based off a simple Unit prototype) which has a script-controlled ability to place buildings, perhaps something similar to how the nanobots mod spawns temporary construction bots to place ghosts down.

The general flow of the functionality i'm aiming for is as follows:
- a player selects a construction unit with selection tool item, [this part is done]

- then selects a building icon from a sidebar GUI and this puts a ghost in the player's hand. [working on gui and background logic for this currently] [what api calls allow me to set the player's cursor to be a ghost of a building?]

-Player places ghost building/s, and the construction unit spawns something like the nanobots to fly out and place the buildings if they are in range. if out of range, construction unit moves to be within range.
as each ghost is placed, added to the unit's own unique build queue list..

- unit goes through a list of ghosts until all are built or the orders cancelled. will probably follow Nexela's nanobots code for most of this part. items are spawned assuming there are some available in the force's global construction stockpile inventory.

Does this sound possible/technically reasonable to implement in your opinions?


The other way is that the construction unit simply acts as a mobile hub for nano-bot style operation in a more general sense - any ghost nearby (blueprint or player placed) which the unit has construction item for (some global stockpile..) will get built. player just moves the construction unit into the area of ghosts, or places the buildings around the unit while it's just chilling in the area. This is probably simpler and more "factorio-ish" than the earlier classic RTS method.

Anyone have any other bright ideas on a lean and brilliant implementation within the mod framework for this kind of unit and feature?

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Implementation of a "Construction Unit" for RTS mod

Post by eradicator »

kyranzor wrote: [what api calls allow me to set the player's cursor to be a ghost of a building?]
None. Except *maybe* a linked custom-input that consumes the normal click and replaces it with alt-build. Otherwise you're left with replacing a normal building with a ghost in on_built.

If you want to enforce a build order it's probably easier to use a fake projectile for animation, and revive the ghost manually instead of using actual bots. Using actual bots with a global stockpile is difficult anyway, because a hypothetical contruction vehicle that uses bots via vehicle grid still needs to somehow access that stockpile. So either you have to have space for every possible item in the contructor, or you need to force-feed it exactly the items it needs. Neither is particularly light-weight cpu cost wise.

What might work with actual bots is making placing buildings via bots free (if that's possible) and then somehow prevent ghosts that can't be build due to item-shortage from being build (either by successfully getting an api request through for toggling buildability per-ghosts, or via...dunno, having a simple entity for *every* building that only looks like a ghost but isn't one.) Then you could simple deduct from the global stockpile in on_built. But have potentially high costs for replacing ghosts with fake ghosts when the stock is low.

A more "classic" (but extremely annoying) approach would be to consume the stockpile on placing the ghost, thus having no stockpile logic for the actual build, but removing the ability to place ghosts of things you don't have in stock.

So the way i see it the most "factorio"-feeling way would be a "mobile roboport" (with small range), but the main problem is the stockpile-interfacing.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

kyranzor
Filter Inserter
Filter Inserter
Posts: 499
Joined: Fri Oct 31, 2014 4:52 pm
Contact:

Re: Implementation of a "Construction Unit" for RTS mod

Post by kyranzor »

Nexela has recommended to me that it's possible to insert a blueprint book with a single entity in it, set by scripting, to the user's cursor. That's good enough for me, to be able to summon something to the user's hand to allow them to place a ghost down, for the constructor units to see and try to build.

I have an idea that supports the 'global stockpile' and the fact you are essentially teleporting an object into the field and building it- using a Total Annihilation style 'nanolathe' particle beam/effect to make it look amazing! People will suspend disbelief and be in awe at how cool it is, and not ask questions about the fact they are being cheesy and building with items remotely.

As I mentioned in reply to the other thread, a vehicle like what we get in AAI programmable vehicles mod, which has an inventory and has a vehicle grid for a small local personal roboport, would be perfect to act as a construction unit. The vehicle simply has to drive up to a loading bay and get all the shit you want to build in the field inserted into it, then you can make it drive off (by commanding it RTS style) and find a place to set up a new base.

This issue:
have to have space for every possible item in the contructor, or you need to force-feed it exactly the items it needs. Neither is particularly light-weight cpu cost wise.
For a vehicle inventory is kind of why I want to have the RTS constructor units not a 100% coverage for building stuff. I'd like to have a set, defined list of entities that the constructor units are allowed to make. Then you can have specialized constructor units, and do technology tiers as well. If each one is limited to 10 different buildings, with various 'themes', this also allows me to have a dynamic 'build menu' GUI interface which as mentioned earlier, summons the ghost in the form of a single entity blueprint to the user's hands, and the user knows that the unit can build that ghost assuming there is some in the global stockpile. I could have the vehicle inventory only 10 stacks, and pre-filtered with the items only it can build... to make it more obvious to the users. However if the vehicle is just a mobile roboport (maybe this is the Tier 3 builder unit? like a mobile commander/base builder unit) it can build everything and this shouldn't be limiting at all.

So in summary:
-non-roboport constructor units, low-tech and plentiful, can only build from a set list, and do so by scripted reviving of ghosts placed by user or by build-bar-summoned blueprint object to place the ghost. Uses global stockpile inventory, pulled from any constructor-warehouse entity.

-high tech mobile construction vehicle with built-in mini roboport with large inventory, places anything the player wants just like a normal roboport. controllable like a unit, similar to AAI vehicles mod.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Implementation of a "Construction Unit" for RTS mod

Post by eradicator »

@one-item-blueprint → doh. yes. ofc. how could i miss that.
kyranzor wrote:using a Total Annihilation style 'nanolathe' particle beam/effect to make it look amazing!
If you make that i'll be in awe because it's so great, and totally annoyed because you made it before i could :P. (Cos that's been on my to-do list for ages, though with a different usecase.)

Different units for different "themes" would depend on how many themes you want. For "just" 2-4 themes it might still work. But having too many different building vehicle types to manage sounds pretty boring. Depends on what kind of themese you imagined. Does a standard factory line with belts, chests, inseters, assemblers, pipes....need more than one vehicle? More than 2?

Also different themese would probably mean that it doesn't work with other mods. (I always attempt to stay compatible with as many other mods as possible)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding discussion”