Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign faction to (some) item and vehicle placement #56110

Merged
merged 7 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 33 additions & 19 deletions data/json/npcs/tacoma_ranch/NPC_ranch_foreman.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
{
"om_terrain": "ranch_camp_56",
"translate_ter": [ { "from": "t_underbrush", "to": "t_dirt", "x": 0, "y": 0 } ],
"place_vehicles": [ { "vehicle": "hippie_van", "x": 10, "y": 10, "rotation": 270, "chance": 100 } ]
"place_vehicles": [ { "vehicle": "hippie_van", "x": 10, "y": 10, "rotation": 270, "chance": 100, "faction": "tacoma_commune" } ]
},
{
"om_terrain": "ranch_camp_65",
Expand Down Expand Up @@ -299,7 +299,7 @@
},
{
"om_terrain": "ranch_camp_56",
"place_vehicles": [ { "vehicle": "flatbed_truck", "x": 18, "y": 3, "rotation": 0, "chance": 100 } ]
"place_vehicles": [ { "vehicle": "flatbed_truck", "x": 18, "y": 3, "rotation": 0, "chance": 100, "faction": "tacoma_commune" } ]
},
{
"om_terrain": "ranch_camp_57",
Expand Down Expand Up @@ -345,7 +345,7 @@
"update_mapgen": [
{
"om_terrain": "ranch_camp_56",
"place_vehicles": [ { "vehicle": "car_chassis", "x": 17, "y": 11, "rotation": 90, "chance": 100 } ]
"place_vehicles": [ { "vehicle": "car_chassis", "x": 17, "y": 11, "rotation": 90, "chance": 100, "faction": "tacoma_commune" } ]
},
{
"om_terrain": "ranch_camp_58",
Expand Down Expand Up @@ -400,12 +400,12 @@
{ "point": "furniture", "id": "f_fireplace", "x": 8, "y": 12 }
],
"place_item": [
{ "item": "log", "x": 3, "y": 11 },
{ "item": "log", "x": 3, "y": 12 },
{ "item": "log", "x": 3, "y": 13 },
{ "item": "log", "x": 11, "y": 11 },
{ "item": "log", "x": 11, "y": 12 },
{ "item": "log", "x": 11, "y": 13 }
{ "item": "log", "x": 3, "y": 11, "faction": "tacoma_commune" },
{ "item": "log", "x": 3, "y": 12, "faction": "tacoma_commune" },
{ "item": "log", "x": 3, "y": 13, "faction": "tacoma_commune" },
{ "item": "log", "x": 11, "y": 11, "faction": "tacoma_commune" },
{ "item": "log", "x": 11, "y": 12, "faction": "tacoma_commune" },
{ "item": "log", "x": 11, "y": 13, "faction": "tacoma_commune" }
]
}
]
Expand Down Expand Up @@ -646,19 +646,33 @@
{
"om_terrain": "ranch_camp_61",
"place_vehicles": [
{ "vehicle": "car", "chance": 100, "rotation": 270, "x": 1, "y": 20 },
{ "vehicle": "cube_van_cheap", "chance": 100, "rotation": 90, "x": 10, "y": 10 },
{ "vehicle": "car_sports", "chance": 100, "rotation": 90, "x": 3, "y": 9 },
{ "vehicle": "flatbed_truck", "chance": 100, "rotation": 270, "x": 10, "y": 23 }
{ "vehicle": "car", "chance": 100, "rotation": 270, "x": 1, "y": 20, "faction": "tacoma_commune" },
{
"vehicle": "cube_van_cheap",
"chance": 100,
"rotation": 90,
"x": 10,
"y": 10,
"faction": "tacoma_commune"
},
{ "vehicle": "car_sports", "chance": 100, "rotation": 90, "x": 3, "y": 9, "faction": "tacoma_commune" },
{
"vehicle": "flatbed_truck",
"chance": 100,
"rotation": 270,
"x": 10,
"y": 23,
"faction": "tacoma_commune"
}
]
},
{
"om_terrain": "ranch_camp_69",
"translate_ter": [ { "from": "t_underbrush", "to": "t_dirt", "x": 0, "y": 0 } ],
"place_vehicles": [
{ "vehicle": "car_chassis", "chance": 100, "rotation": 0, "x": 3, "y": 14 },
{ "vehicle": "pickup", "chance": 100, "rotation": 0, "x": 8, "y": 15 },
{ "vehicle": "schoolbus", "chance": 100, "rotation": 135, "x": 22, "y": 13 }
{ "vehicle": "car_chassis", "chance": 100, "rotation": 0, "x": 3, "y": 14, "faction": "tacoma_commune" },
{ "vehicle": "pickup", "chance": 100, "rotation": 0, "x": 8, "y": 15, "faction": "tacoma_commune" },
{ "vehicle": "schoolbus", "chance": 100, "rotation": 135, "x": 22, "y": 13, "faction": "tacoma_commune" }
]
}
]
Expand Down Expand Up @@ -696,7 +710,7 @@
{
"om_terrain": "ranch_camp_69",
"translate_ter": [ { "from": "t_underbrush", "to": "t_dirt", "x": 0, "y": 0 } ],
"place_vehicles": [ { "vehicle": "cube_van", "chance": 100, "rotation": 180, "x": 13, "y": 15 } ]
"place_vehicles": [ { "vehicle": "cube_van", "chance": 100, "rotation": 180, "x": 13, "y": 15, "faction": "tacoma_commune" } ]
}
]
}
Expand Down Expand Up @@ -730,7 +744,7 @@
{
"om_terrain": "ranch_camp_70",
"translate_ter": [ { "from": "t_underbrush", "to": "t_dirt", "x": 0, "y": 0 } ],
"place_vehicles": [ { "vehicle": "car_mini", "chance": 100, "rotation": 45, "x": 8, "y": 3 } ]
"place_vehicles": [ { "vehicle": "car_mini", "chance": 100, "rotation": 45, "x": 8, "y": 3, "faction": "tacoma_commune" } ]
}
]
}
Expand Down Expand Up @@ -770,7 +784,7 @@
{
"om_terrain": "ranch_camp_61",
"translate_ter": [ { "from": "t_underbrush", "to": "t_dirt", "x": 0, "y": 0 } ],
"place_vehicles": [ { "vehicle": "ambulance", "chance": 100, "rotation": 90, "x": 16, "y": 5 } ]
"place_vehicles": [ { "vehicle": "ambulance", "chance": 100, "rotation": 90, "x": 16, "y": 5, "faction": "tacoma_commune" } ]
}
]
}
Expand Down
29 changes: 17 additions & 12 deletions data/json/npcs/tacoma_ranch/mission_mapgen_tacoma_commune.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
"object": {
"mapgensize": [ 2, 2 ],
"rows": [
"##",
"B#",
" "
],
"terrain": { "#": "t_dirt" },
"furniture": { "#": "f_makeshift_bed" }
"furniture": { "#": "f_makeshift_bed", "B": "f_makeshift_bed" },
"item": { "B": { "item": "blanket", "faction": "tacoma_commune" } }
}
},
{
Expand Down Expand Up @@ -430,7 +431,7 @@
],
"terrain": { "w": "t_wall", ".": "t_dirtfloor", "+": "t_door_c", "r": "t_dirtfloor", "c": "t_dirtfloor", "b": "t_dirtfloor" },
"furniture": { "r": "f_rack", "c": "f_counter", "b": "f_makeshift_bed" },
"place_vehicles": [ { "vehicle": "armored_car", "chance": 100, "rotation": 0, "x": 15, "y": 7 } ],
"place_vehicles": [ { "vehicle": "armored_car", "chance": 100, "rotation": 0, "x": 15, "y": 7, "faction": "tacoma_commune" } ],
"place_npcs": [ { "class": "ranch_scrapper_1", "x": 13, "y": 12 } ]
}
},
Expand Down Expand Up @@ -525,7 +526,7 @@
" "
],
"terrain": { "w": "t_wall", ".": "t_dirt", "[": "t_window_boarded_noglass" },
"place_item": [ { "item": "ax", "x": 13, "y": 18 } ]
"place_item": [ { "item": "ax", "x": 13, "y": 18, "faction": "tacoma_commune" } ]
}
},
{
Expand Down Expand Up @@ -767,7 +768,11 @@
],
"terrain": { "r": "t_dirtfloor", "W": "t_wall_log", ".": "t_dirtfloor" },
"furniture": { "r": "f_rack" },
"place_item": [ { "item": "frame", "x": 3, "y": 6 }, { "item": "frame", "x": 3, "y": 7 }, { "item": "frame", "x": 3, "y": 8 } ]
"place_item": [
{ "item": "frame", "x": 3, "y": 6, "faction": "tacoma_commune" },
{ "item": "frame", "x": 3, "y": 7, "faction": "tacoma_commune" },
{ "item": "frame", "x": 3, "y": 8, "faction": "tacoma_commune" }
]
}
},
{
Expand Down Expand Up @@ -817,13 +822,13 @@
"terrain": { "r": "t_dirtfloor", "W": "t_wall_log", ".": "t_dirtfloor", "m": "t_dirtfloor", "M": "t_dirtfloor", "c": "t_conveyor" },
"furniture": { "m": "f_machinery_old", "M": "f_machinery_heavy", "r": "f_rack" },
"place_item": [
{ "item": "log", "x": 3, "y": 0 },
{ "item": "log", "x": 3, "y": 1 },
{ "item": "log", "x": 3, "y": 1 },
{ "item": "log", "x": 0, "y": 1, "amount": [ 1, 5 ] },
{ "item": "log", "x": 1, "y": 1, "amount": [ 1, 5 ] },
{ "item": "2x4", "x": 3, "y": 9, "amount": [ 1, 10 ] },
{ "item": "log", "x": 3, "y": 2 }
{ "item": "log", "x": 3, "y": 0, "faction": "tacoma_commune" },
{ "item": "log", "x": 3, "y": 1, "faction": "tacoma_commune" },
{ "item": "log", "x": 3, "y": 1, "faction": "tacoma_commune" },
{ "item": "log", "x": 0, "y": 1, "faction": "tacoma_commune", "amount": [ 1, 5 ] },
{ "item": "log", "x": 1, "y": 1, "faction": "tacoma_commune", "amount": [ 1, 5 ] },
{ "item": "2x4", "x": 3, "y": 9, "faction": "tacoma_commune", "amount": [ 1, 10 ] },
{ "item": "log", "x": 3, "y": 2, "faction": "tacoma_commune" }
],
"place_npcs": [ { "class": "ranch_woodcutter_1", "x": 4, "y": 7 } ]
}
Expand Down
12 changes: 7 additions & 5 deletions doc/MAPGEN.md
Original file line number Diff line number Diff line change
Expand Up @@ -808,11 +808,12 @@ Places a gas pump with fuel in it.

### Place items from an item group with "items"

| Field | Description
| --- | ---
| item | (required, string or itemgroup object) the item group to use.
| chance | (optional, integer or min/max array) x in 100 chance that a loop will continue to spawn items from the group (which itself may spawn multiple items or not depending on its type, see `ITEM_SPAWN.md`), unless the chance is 100, in which case it will trigger the item group spawn exactly 1 time (see `map::place_items`).
| repeat | (optional, integer or min/max array) the number of times to repeat this placement, default is 1.
| Field | Description
| --- | ---
| item | (required, string or itemgroup object) the item group to use.
| chance | (optional, integer or min/max array) x in 100 chance that a loop will continue to spawn items from the group (which itself may spawn multiple items or not depending on its type, see `ITEM_SPAWN.md`), unless the chance is 100, in which case it will trigger the item group spawn exactly 1 time (see `map::place_items`).
| repeat | (optional, integer or min/max array) the number of times to repeat this placement, default is 1.
| faction | (optional, string) the faction that owns these items.


### Place monsters from a monster group with "monsters"
Expand All @@ -835,6 +836,7 @@ The actual monsters are spawned when the map is loaded. Fields:
| rotation | (optional, integer) the direction the vehicle faces.
| fuel | (optional, integer) the fuel status. Default is -1 which makes the tanks 1-7% full. Positive values are interpreted as percentage of the vehicles tanks to fill (e.g. 100 means completely full).
| status | (optional, integer) default is -1 (light damage), a value of 0 means perfect condition, 1 means heavily damaged.
| faction | (optional, string) faction this vehicle belongs to.

Note that vehicles cannot be placed over overmap boundaries. So it needs to be 24 tiles long at most.

Expand Down
5 changes: 3 additions & 2 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4378,7 +4378,7 @@ void map::spawn_artifact( const tripoint &p, const relic_procgen_id &id,

void map::spawn_item( const tripoint &p, const itype_id &type_id, const unsigned quantity,
const int charges, const time_point &birthday, const int damlevel, const std::set<flag_id> &flags,
const std::string &variant )
const std::string &variant, const std::string &faction )
{
if( type_id.is_null() ) {
return;
Expand All @@ -4389,12 +4389,13 @@ void map::spawn_item( const tripoint &p, const itype_id &type_id, const unsigned
}
// recurse to spawn (quantity - 1) items
for( size_t i = 1; i < quantity; i++ ) {
spawn_item( p, type_id, 1, charges, birthday, damlevel, flags );
spawn_item( p, type_id, 1, charges, birthday, damlevel, flags, variant, faction );
}
// migrate and spawn the item
itype_id mig_type_id = item_controller->migrate_id( type_id );
item new_item( mig_type_id, birthday );
new_item.set_itype_variant( variant );
new_item.set_owner( faction_id( faction ) );
if( one_in( 3 ) && new_item.has_flag( flag_VARSIZE ) ) {
new_item.set_flag( flag_FIT );
}
Expand Down
35 changes: 21 additions & 14 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -1215,29 +1215,34 @@ class map
void spawn_item( const tripoint &p, const itype_id &type_id,
unsigned quantity = 1, int charges = 0,
const time_point &birthday = calendar::start_of_cataclysm, int damlevel = 0,
const std::set<flag_id> &flags = {}, const std::string &variant = "" );
const std::set<flag_id> &flags = {}, const std::string &variant = "",
const std::string &faction = "" );
void spawn_item( const point &p, const itype_id &type_id,
unsigned quantity = 1, int charges = 0,
const time_point &birthday = calendar::start_of_cataclysm, int damlevel = 0,
const std::set<flag_id> &flags = {}, const std::string &variant = "" ) {
const std::set<flag_id> &flags = {}, const std::string &variant = "",
const std::string &faction = "" ) {
spawn_item( tripoint( p, abs_sub.z() ), type_id, quantity, charges, birthday, damlevel, flags,
variant );
variant, faction );
}

// FIXME: remove these overloads and require spawn_item to take an
// itype_id
void spawn_item( const tripoint &p, const std::string &type_id,
unsigned quantity = 1, int charges = 0,
const time_point &birthday = calendar::start_of_cataclysm, int damlevel = 0,
const std::set<flag_id> &flags = {}, const std::string &variant = "" ) {
spawn_item( p, itype_id( type_id ), quantity, charges, birthday, damlevel, flags, variant );
const std::set<flag_id> &flags = {}, const std::string &variant = "",
const std::string &faction = "" ) {
spawn_item( p, itype_id( type_id ), quantity, charges, birthday, damlevel, flags, variant,
faction );
}
void spawn_item( const point &p, const std::string &type_id,
unsigned quantity = 1, int charges = 0,
const time_point &birthday = calendar::start_of_cataclysm, int damlevel = 0,
const std::set<flag_id> &flags = {}, const std::string &variant = "" ) {
const std::set<flag_id> &flags = {}, const std::string &variant = "",
const std::string &faction = "" ) {
spawn_item( tripoint( p, abs_sub.z() ), type_id, quantity, charges, birthday, damlevel, flags,
variant );
variant, faction );
}
units::volume max_volume( const tripoint &p );
units::volume free_volume( const tripoint &p );
Expand Down Expand Up @@ -1334,12 +1339,14 @@ class map
*/
std::vector<item *> place_items(
const item_group_id &group_id, int chance, const tripoint &p1, const tripoint &p2,
bool ongrass, const time_point &turn, int magazine = 0, int ammo = 0 );
bool ongrass, const time_point &turn, int magazine = 0, int ammo = 0,
const std::string &faction = "" );
std::vector<item *> place_items(
const item_group_id &group_id, int chance, const point &p1, const point &p2,
bool ongrass, const time_point &turn, int magazine = 0, int ammo = 0 ) {
bool ongrass, const time_point &turn, int magazine = 0, int ammo = 0,
const std::string &faction = "" ) {
return place_items( group_id, chance, tripoint( p1, abs_sub.z() ),
tripoint( p2, abs_sub.z() ), ongrass, turn, magazine, ammo );
tripoint( p2, abs_sub.z() ), ongrass, turn, magazine, ammo, faction );
}
/**
* Place items from an item group at p. Places as much items as the item group says.
Expand Down Expand Up @@ -1618,16 +1625,16 @@ class map

vehicle *add_vehicle( const vgroup_id &type, const tripoint &p, const units::angle &dir,
int init_veh_fuel = -1, int init_veh_status = -1,
bool merge_wrecks = true );
bool merge_wrecks = true, const std::string &faction = "" );
vehicle *add_vehicle( const vgroup_id &type, const point &p, const units::angle &dir,
int init_veh_fuel = -1, int init_veh_status = -1,
bool merge_wrecks = true );
bool merge_wrecks = true, const std::string &faction = "" );
vehicle *add_vehicle( const vproto_id &type, const tripoint &p, const units::angle &dir,
int init_veh_fuel = -1, int init_veh_status = -1,
bool merge_wrecks = true );
bool merge_wrecks = true, const std::string &faction = "" );
vehicle *add_vehicle( const vproto_id &type, const point &p, const units::angle &dir,
int init_veh_fuel = -1, int init_veh_status = -1,
bool merge_wrecks = true );
bool merge_wrecks = true, const std::string &faction = "" );
// Light/transparency
float light_transparency( const tripoint &p ) const;
// Assumes 0,0 is light map center
Expand Down
Loading