Skip to content

Commit 4b86efe

Browse files
authored
feat: Allow vehicle palettes to use fuel and turret parts (#8302)
* feat: Allow vehicle palettes to have fuel and turret parts * let the tree kill my line count * stupid docs * whoops
1 parent a95f3e4 commit 4b86efe

File tree

3 files changed

+47
-90
lines changed

3 files changed

+47
-90
lines changed

data/json/vehicles/aircraft_other.json

Lines changed: 26 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -227,55 +227,20 @@
227227
"O": [ "airship_balloon_external" ],
228228
"P": [ "propeller_wood" ],
229229
"t": [ "frame_wood_cross", "wood box", "airship_balloon" ],
230-
"X": [ "frame_wood_cross", "door_wood_opaque", "airship_balloon" ]
230+
"X": [ "frame_wood_cross", "door_wood_opaque", "airship_balloon" ],
231+
"o": [ "frame_wood_cross", "wood box", "roof_wood", { "part": "fuel_bunker", "fuel": "coal_lump" }, "airship_balloon" ],
232+
"T": [
233+
"frame_wood_cross",
234+
"seat_wood",
235+
"turret_mount_manual_wood",
236+
{
237+
"ammo_types": [ "rock", "sling_bullet", "ammo_ballista_wood", "ammo_ballista_iron" ],
238+
"part": "mounted_launcher_ballista",
239+
"ammo": 75,
240+
"ammo_qty": [ 1, 10 ]
241+
}
242+
]
231243
},
232-
"parts": [
233-
{
234-
"x": -9,
235-
"y": 0,
236-
"parts": [ "frame_wood_cross", "wood box", "roof_wood", { "part": "fuel_bunker", "fuel": "coal_lump" }, "airship_balloon" ]
237-
},
238-
{
239-
"x": -9,
240-
"y": 1,
241-
"parts": [ "frame_wood_cross", "wood box", "roof_wood", { "part": "fuel_bunker", "fuel": "coal_lump" }, "airship_balloon" ]
242-
},
243-
{
244-
"x": -9,
245-
"y": -1,
246-
"parts": [ "frame_wood_cross", "wood box", "roof_wood", { "part": "fuel_bunker", "fuel": "coal_lump" }, "airship_balloon" ]
247-
},
248-
{
249-
"x": 2,
250-
"y": 2,
251-
"parts": [
252-
"frame_wood_cross",
253-
"seat_wood",
254-
"turret_mount_manual_wood",
255-
{
256-
"ammo_types": [ "rock", "sling_bullet", "ammo_ballista_wood", "ammo_ballista_iron" ],
257-
"part": "mounted_launcher_ballista",
258-
"ammo": 75,
259-
"ammo_qty": [ 1, 10 ]
260-
}
261-
]
262-
},
263-
{
264-
"x": 2,
265-
"y": -2,
266-
"parts": [
267-
"frame_wood_cross",
268-
"seat_wood",
269-
"turret_mount_manual_wood",
270-
{
271-
"ammo_types": [ "rock", "sling_bullet", "ammo_ballista_wood", "ammo_ballista_iron" ],
272-
"part": "mounted_launcher_ballista",
273-
"ammo": 75,
274-
"ammo_qty": [ 1, 1 ]
275-
}
276-
]
277-
}
278-
],
279244
"items": [
280245
{ "x": 1, "y": 2, "chance": 50, "item_groups": [ "supplies_skyfarer_ballista" ] },
281246
{ "x": 1, "y": -2, "chance": 50, "item_groups": [ "supplies_skyfarer_ballista" ] }
@@ -309,35 +274,20 @@
309274
"E": [ "frame_wood_horizontal", "woodhalfboard_horizontal", "engine_steam_small", "plating_wood", "airship_balloon" ],
310275
"O": [ "airship_balloon_external" ],
311276
"P": [ "propeller_wood" ],
312-
"t": [ "frame_wood_cross", "wood box", "airship_balloon" ]
277+
"t": [ "frame_wood_cross", "wood box", "airship_balloon" ],
278+
"o": [ "frame_wood_cross", "wood box", { "part": "fuel_bunker", "fuel": "coal_lump" }, "airship_balloon" ],
279+
"T": [
280+
"frame_wood_cross",
281+
"seat_wood",
282+
"turret_mount_manual_wood",
283+
{
284+
"ammo_types": [ "rock", "sling_bullet", "ammo_ballista_wood", "ammo_ballista_iron" ],
285+
"part": "mounted_launcher_ballista",
286+
"ammo": 75,
287+
"ammo_qty": [ 1, 10 ]
288+
}
289+
]
313290
},
314-
"parts": [
315-
{
316-
"x": -2,
317-
"y": 0,
318-
"parts": [ "frame_wood_cross", "wood box", { "part": "fuel_bunker", "fuel": "coal_lump" }, "airship_balloon" ]
319-
},
320-
{
321-
"x": -2,
322-
"y": 2,
323-
"parts": [ "frame_wood_cross", "wood box", { "part": "fuel_bunker", "fuel": "coal_lump" }, "airship_balloon" ]
324-
},
325-
{
326-
"x": 0,
327-
"y": 2,
328-
"parts": [
329-
"frame_wood_cross",
330-
"seat_wood",
331-
"turret_mount_manual_wood",
332-
{
333-
"ammo_types": [ "rock", "sling_bullet", "ammo_ballista_wood", "ammo_ballista_iron" ],
334-
"part": "mounted_launcher_ballista",
335-
"ammo": 75,
336-
"ammo_qty": [ 1, 10 ]
337-
}
338-
]
339-
}
340-
],
341291
"items": [ { "x": 1, "y": 1, "chance": 75, "item_groups": [ "supplies_skyfarer_ballista" ] } ]
342292
},
343293
{

docs/en/mod/json/reference/vehicles/vehicles_spawning.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Vehicle prototypes do not currently accept copy-from
1818
],
1919
"blueprint_origin": { "x": 10, "y": 3 } // Used by palettes to locate the offset
2020
"palette": { // Palette used by blueprint to set parts on a tile
21-
"O": [ "airship_balloon_external" ] // Can only be an array of strings, no part objects
21+
"O": [ "airship_balloon_external" ] // Can only be an array not one string
22+
"J": [ { "part": "tank", "fuel": "gasoline" }, "battery_car" ], // All part types supported
2223
}
2324
"parts": [ // Parts list
2425
{ "x": 0, "y": 0, "part": "frame" }, // Part definition, positive x direction is up,

src/veh_type.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,19 +1133,26 @@ void vehicle_prototype::load( const JsonObject &jo )
11331133
if( jo.has_member( "palette" ) ) {
11341134
std::map< char, JsonArray > string_palette;
11351135
for( const JsonMember member : jo.get_object( "palette" ) ) {
1136-
std::vector<std::string> members;
1137-
for( const auto entry : member.get_array() ) {
1138-
members.push_back( entry );
1139-
}
11401136
string_palette[member.name().at( 0 )] = member.get_array();
11411137
}
1142-
std::map< char, std::vector<vpart_id> > veh_palette;
1143-
for( auto const character : string_palette ) {
1144-
for( std::string part : character.second ) {
1138+
std::map< char, std::vector<part_def> > veh_palette;
1139+
for( auto const &character : string_palette ) {
1140+
for( JsonValue part : character.second ) {
1141+
part_def pt;
1142+
if( part.test_string() ) {
1143+
pt.part = vpart_id( part.get_string() );
1144+
} else {
1145+
JsonObject realpart = part.get_object();
1146+
pt.part = vpart_id( realpart.get_string( "part" ) );
1147+
assign( realpart, "ammo", pt.with_ammo, true, 0, 100 );
1148+
assign( realpart, "ammo_types", pt.ammo_types, true );
1149+
assign( realpart, "ammo_qty", pt.ammo_qty, true, 0 );
1150+
assign( realpart, "fuel", pt.fuel, true );
1151+
}
11451152
if( !veh_palette.contains( character.first ) ) {
1146-
veh_palette[character.first] = { vpart_id( part ) };
1153+
veh_palette[character.first] = { pt };
11471154
} else {
1148-
veh_palette[character.first].push_back( vpart_id( part ) );
1155+
veh_palette[character.first].push_back( pt );
11491156
}
11501157
}
11511158
}
@@ -1156,17 +1163,16 @@ void vehicle_prototype::load( const JsonObject &jo )
11561163
for( char character : row ) {
11571164
x += 1;
11581165
if( !veh_palette.contains( character ) ) { continue; }
1159-
for( auto const part : veh_palette.at( character ) ) {
1160-
part_def pt;
1166+
for( auto part : veh_palette.at( character ) ) {
1167+
part_def pt = part;
11611168
pt.pos = point( x, y );
1162-
pt.part = part;
11631169
vproto.parts.push_back( pt );
11641170
}
11651171
}
11661172
y += 1;
11671173
}
11681174
} else {
1169-
// This still has to be optional in cases where old mods or places are still using it for only display purposes
1175+
// This still has to be optional in cases where it is used only for display purposes
11701176
jo.get_array( "blueprint" );
11711177
}
11721178
}

0 commit comments

Comments
 (0)