Multi-Tile Vehicle Parts

So, I’ve been giving some thought to multi-tile vehicle parts, and how to make that work. I was planning to start with tanks, and expand from there. However, I figured I’d consult with the forums for both design and implementation ideas.

How I was thinking of having it work now: when adding a part (or in initial spawning), if it’s a multi-tile part, check the tiles next to it. If they’re a the same type, add them to a list, and continue iterating. Calculate the stats (for example, for a large tank’s volume). Additional code would be needed when a part is damaged. I’d have to make sure it just became a damaged large tank, rather than a smaller tank.

I’d also be using this system to implement constructions later on (previous topic: http://smf.cataclysmdda.com/index.php?topic=8171.msg187348#msg187348). Yes, it’s been a while, I had some IRL stuff to take care of.

Anyway, just wanted to jot some of my thoughts down here for feedback and future reference.

I’d do it like multitile doors: by handling the multi-tileness where required.

For example, when calculating total gas storage, you don’t need to do anything, but for draining 5 gas you’d have to make sure all the neighbors have similar amount of gas after that.

Remember that finding neighbors is moderately expensive - it requires you to go through all parts of the vehicle every single time you do it. So it is pretty important that you don’t use the “part_at” type functions to find each of 4 possible neighbors, but rather build a map of parts that could be neighbors once per turn/calculation and then operate on that. At least if you want to access the multi-tile types often (for example, want multi-tile gas tanks).

Remembering the list of neighbors could work, but forget about the idea of updating it from the current state - you’ll have to recalculate it from scratch every time you install/wreck a part. This won’t be very expensive, as it parts getting installed/wrecked doesn’t happen a lot.

If you want to keep all the multi-tile components rather than just neighbors, calculate the list at once and then copy it to all components. ie. go through the entire vehicle, build all lists of parts that are components of multi-tile “megaparts”, then copy those lists to components.

To sum up:

[ul][li]Keep a list of neighbors. List has to be of part ids (“part number 30”) rather than part positions[/li]
[li]Make sure you recalculate the list when ids change (part is added/removed)[/li]
[li]Avoid part_at functions for finding neighbors, they are slow. Instead build a map of same-type parts. Map can be point->id[/li][/ul]

Ok, rough plans of what I’ve got so far:

Add a “multipart” flag to vehicle parts, as well as a string for “multipart type”.

To vehicles, add a vector of vectors of parts, megapart_list. This will contain the lists of part ids in each megapart. I’m not sure if this is the best way to do it, or a new struct.

Iterate over the vehicle parts during refresh, make a list of parts flagged multipart. After iterating over the part list, begin iterating over the parts with multipart list. (Use a temp int to keep track of the megapart id) Remove the ids from that parts with multipart list when iterated over, and add to the list of compiled megaparts (the either vector of vectors or struct mentioned earlier). Run a check_neighbors function (see remove_part/is_connected, be sure to pass int for megapart id). If the part is not a multipart of the same multipart_type, go to the next neighbor. If it is and is still in the list of parts with the multipart flag, recursively call check_neighbors(int that_part_id, int same_megapart_id). This should iterate over all neighboring parts and compile then into a list, while allowing for multiple parts with a multipart flag but different types on the same tile.

So that’s what I’m thinking data wise. For the part info, that’d be handled on a type by type basis.

This is one thing I cant wait to see in CDDA.

Having a large vehicle I can unload a small quad bike from and go scouting :open_mouth:

[quote=“stk2008, post:4, topic:9433”]This is one thing I cant wait to see in CDDA.

Having a large vehicle I can unload a small quad bike from and go scouting :O[/quote]
Except this thread is about multitile vehicle parts like gas tank that needs to be put on 2 tiles instead of one :stuck_out_tongue:

How about gas tanks that are adjacent and concurrent act as one gas tank? Would that fit the thread? :stuck_out_tongue:

[quote=“Vorchar, post:5, topic:9433”][quote=“stk2008, post:4, topic:9433”]This is one thing I cant wait to see in CDDA.

Having a large vehicle I can unload a small quad bike from and go scouting :O[/quote]
Except this thread is about multitile vehicle parts like gas tank that needs to be put on 2 tiles instead of one :p[/quote]

Oh I see LOL :stuck_out_tongue:

Sorry :stuck_out_tongue: