Skip to content

Commit

Permalink
Add field_remove and clear back bay and garage (#56984)
Browse files Browse the repository at this point in the history
* Add field_remove and clear back bay

* Somehow doc updates got lost

* Cleanup back bay as well as the garage
  • Loading branch information
haveric authored Apr 22, 2022
1 parent 60a7336 commit 5c9be55
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,9 @@
{ "u_spawn_item": "FMCNote", "count": 5 },
{ "u_add_var": "Boris_mission_1", "type": "mission", "context": "completed", "value": "yes" },
{ "npc_first_topic": "TALK_REFUGEE_Boris_1b" },
{ "u_adjust_var": "refugee_happiness", "type": "counter", "context": "refugee_center", "adjustment": 3 }
{ "u_adjust_var": "refugee_happiness", "type": "counter", "context": "refugee_center", "adjustment": 3 },
{ "mapgen_update": "boris_cleanup_garage", "om_terrain": "evac_center_8" },
{ "mapgen_update": "boris_cleanup_back_bay", "om_terrain": "evac_center_9" }
]
}
},
Expand Down Expand Up @@ -529,5 +531,36 @@
"type": "TOOL",
"name": { "str": "Ash's laptop computer" },
"description": "A small, somewhat worn-out laptop computer. The flip-top is decorated with various stickers."
},
{
"type": "mapgen",
"update_mapgen_id": "boris_cleanup_garage",
"method": "json",
"object": {
"set": [
{ "square": "furniture", "id": "f_clear", "x": 6, "y": 3, "x2": 17, "y2": 3 },
{ "square": "furniture", "id": "f_clear", "x": 3, "y": 4, "x2": 20, "y2": 14 },
{ "square": "furniture", "id": "f_clear", "x": 4, "y": 15, "x2": 20, "y2": 15 },
{ "square": "furniture", "id": "f_clear", "x": 5, "y": 16, "x2": 18, "y2": 16 },
{ "square": "item_remove", "x": 3, "y": 3, "x2": 20, "y2": 16 },
{ "square": "item_remove", "x": 21, "y": 12, "x2": 23, "y2": 15 },
{ "square": "field_remove", "x": 2, "y": 2, "x2": 21, "y2": 17 },
{ "square": "field_remove", "x": 22, "y": 11, "x2": 23, "y2": 17 },
{ "square": "terrain", "id": "t_rdoor_c", "x": 21, "y": 13, "x2": 21, "y2": 14 }
]
}
},
{
"type": "mapgen",
"update_mapgen_id": "boris_cleanup_back_bay",
"method": "json",
"object": {
"set": [
{ "square": "furniture", "id": "f_clear", "x": 0, "y": 4, "x2": 17, "y2": 22 },
{ "square": "item_remove", "x": 0, "y": 4, "x2": 17, "y2": 22 },
{ "square": "field_remove", "x": 0, "y": 4, "x2": 17, "y2": 22 },
{ "square": "furniture", "id": "f_locker", "x": 17, "y": 6, "x2": 17, "y2": 19 }
]
}
}
]
12 changes: 6 additions & 6 deletions doc/MAPGEN.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ See terrain.json, furniture.json, and trap.json for "id" strings.

| Field | Description
| --- | ---
| point | Allowed values: `"terrain"`, `"furniture"`, `"trap"`, `"trap_remove"`, `"item_remove"` `"radiation"`, `"variable"`
| id | Terrain, furniture, trap ID or the variable's name. Examples: `"id": "f_counter"`, `"id": "tr_beartrap"`. Omit for "radiation" or "item_remove". For `trap_remove` if tr_null is used any traps present will be removed.
| point | Allowed values: `"terrain"`, `"furniture"`, `"trap"`, `"trap_remove"`, `"item_remove"`, `"field_remove"`, `"radiation"`, `"variable"`
| id | Terrain, furniture, trap ID or the variable's name. Examples: `"id": "f_counter"`, `"id": "tr_beartrap"`. Omit for "radiation", "item_remove", and "field_remove". For `trap_remove` if tr_null is used any traps present will be removed.
| x, y | X, Y coordinates. Value from `0-23`, or range `[ 0-23, 0-23 ]` for a random value in that range. Example: `"x": 12, "y": [ 5, 15 ]`
| amount | Radiation amount. Value from `0-100`.
| chance | (optional) One-in-N chance to apply
Expand All @@ -482,8 +482,8 @@ Example:

| Field | Description
| --- | ---
| line | Allowed values: `"terrain"`, `"furniture"`, `"trap"`, `"radiation"`, `"trap_remove"`, `"item_remove"`
| id | Terrain, furniture, or trap ID. Examples: `"id": "f_counter"`, `"id": "tr_beartrap"`. Omit for "radiation". For `trap_remove` if tr_null is used any traps present will be removed.
| line | Allowed values: `"terrain"`, `"furniture"`, `"trap"`, `"radiation"`, `"trap_remove"`, `"item_remove"`, `"field_remove"`
| id | Terrain, furniture, or trap ID. Examples: `"id": "f_counter"`, `"id": "tr_beartrap"`. Omit for "radiation", "item_remove", and "field_remove". For `trap_remove` if tr_null is used any traps present will be removed.
| x, y | Start X, Y coordinates. Value from `0-23`, or range `[ 0-23, 0-23 ]` for a random value in that range. Example: `"x": 12, "y": [ 5, 15 ]`
| x2, y2 | End X, Y coordinates. Value from `0-23`, or range `[ 0-23, 0-23 ]` for a random value in that range. Example: `"x": 22, "y": [ 15, 20 ]`
| amount | Radiation amount. Value from `0-100`.
Expand All @@ -506,8 +506,8 @@ Example:

| Field | Description
| --- | ---
| square | Allowed values: `"terrain"`, `"furniture"`, `"trap"`, `"radiation"`, `"trap_remove"`, `"item_remove"`
| id | Terrain, furniture, or trap ID. Examples: `"id": "f_counter"`, `"id": "tr_beartrap"`. Omit for "radiation" and "item_remove". For `trap_remove` if tr_null is used any traps present will be removed.
| square | Allowed values: `"terrain"`, `"furniture"`, `"trap"`, `"radiation"`, `"trap_remove"`, `"item_remove"`, `"field_remove"`
| id | Terrain, furniture, or trap ID. Examples: `"id": "f_counter"`, `"id": "tr_beartrap"`. Omit for "radiation", "item_remove", and "field_remove". For `trap_remove` if tr_null is used any traps present will be removed.
| x, y | Top-left corner of square.
| x2, y2 | Bottom-right corner of square.

Expand Down
30 changes: 29 additions & 1 deletion src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ void mapgen_function_json_base::setup_setmap( const JsonArray &parray )
setmap_opmap[ "trap" ] = JMAPGEN_SETMAP_TRAP;
setmap_opmap[ "trap_remove" ] = JMAPGEN_SETMAP_TRAP_REMOVE;
setmap_opmap[ "item_remove" ] = JMAPGEN_SETMAP_ITEM_REMOVE;
setmap_opmap[ "field_remove" ] = JMAPGEN_SETMAP_FIELD_REMOVE;
setmap_opmap[ "radiation" ] = JMAPGEN_SETMAP_RADIATION;
setmap_opmap[ "bash" ] = JMAPGEN_SETMAP_BASH;
setmap_opmap[ "variable" ] = JMAPGEN_SETMAP_VARIABLE;
Expand Down Expand Up @@ -930,7 +931,8 @@ void mapgen_function_json_base::setup_setmap( const JsonArray &parray )
}
if( tmpop == JMAPGEN_SETMAP_RADIATION ) {
tmp_i = jmapgen_int( pjo, "amount" );
} else if( tmpop == JMAPGEN_SETMAP_BASH || tmpop == JMAPGEN_SETMAP_ITEM_REMOVE ) {
} else if( tmpop == JMAPGEN_SETMAP_BASH || tmpop == JMAPGEN_SETMAP_ITEM_REMOVE ||
tmpop == JMAPGEN_SETMAP_FIELD_REMOVE ) {
//suppress warning
} else if( tmpop == JMAPGEN_SETMAP_VARIABLE ) {
string_val = "npctalk_var_" + pjo.get_string( "id" );
Expand Down Expand Up @@ -4205,12 +4207,15 @@ mapgen_phase jmapgen_setmap::phase() const
case JMAPGEN_SETMAP_TRAP:
case JMAPGEN_SETMAP_TRAP_REMOVE:
case JMAPGEN_SETMAP_ITEM_REMOVE:
case JMAPGEN_SETMAP_FIELD_REMOVE:
case JMAPGEN_SETMAP_LINE_TRAP:
case JMAPGEN_SETMAP_LINE_TRAP_REMOVE:
case JMAPGEN_SETMAP_LINE_ITEM_REMOVE:
case JMAPGEN_SETMAP_LINE_FIELD_REMOVE:
case JMAPGEN_SETMAP_SQUARE_TRAP:
case JMAPGEN_SETMAP_SQUARE_TRAP_REMOVE:
case JMAPGEN_SETMAP_SQUARE_ITEM_REMOVE:
case JMAPGEN_SETMAP_SQUARE_FIELD_REMOVE:
return mapgen_phase::default_;
case JMAPGEN_SETMAP_RADIATION:
case JMAPGEN_SETMAP_BASH:
Expand Down Expand Up @@ -4276,6 +4281,10 @@ bool jmapgen_setmap::apply( const mapgendata &dat, const point &offset ) const
m.i_clear( point( x_get(), y_get() ) );
}
break;
case JMAPGEN_SETMAP_FIELD_REMOVE: {
mremove_fields( &m, point( x_get(), y_get() ) );
}
break;
case JMAPGEN_SETMAP_BASH: {
m.bash( tripoint( x_get(), y_get(), m.get_abs_sub().z() ), 9999 );
}
Expand Down Expand Up @@ -4321,6 +4330,14 @@ bool jmapgen_setmap::apply( const mapgendata &dat, const point &offset ) const
}
}
break;
case JMAPGEN_SETMAP_LINE_FIELD_REMOVE: {
const std::vector<point> line = line_to( point( x_get(), y_get() ), point( x2_get(), y2_get() ),
0 );
for( const point &i : line ) {
mremove_fields( &m, i );
}
}
break;
case JMAPGEN_SETMAP_LINE_RADIATION: {
const std::vector<point> line = line_to( point( x_get(), y_get() ), point( x2_get(), y2_get() ),
0 );
Expand Down Expand Up @@ -4374,6 +4391,17 @@ bool jmapgen_setmap::apply( const mapgendata &dat, const point &offset ) const
}
}
break;
case JMAPGEN_SETMAP_SQUARE_FIELD_REMOVE: {
const point c( x_get(), y_get() );
const int cx2 = x2_get();
const int cy2 = y2_get();
for( int tx = c.x; tx <= cx2; tx++ ) {
for( int ty = c.y; ty <= cy2; ty++ ) {
mremove_fields( &m, point( tx, ty ) );
}
}
}
break;
case JMAPGEN_SETMAP_SQUARE_RADIATION: {
const point c2( x_get(), y_get() );
const int cx2 = x2_get();
Expand Down
5 changes: 4 additions & 1 deletion src/mapgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ enum jmapgen_setmap_op {
JMAPGEN_SETMAP_RADIATION,
JMAPGEN_SETMAP_TRAP_REMOVE,
JMAPGEN_SETMAP_ITEM_REMOVE,
JMAPGEN_SETMAP_FIELD_REMOVE,
JMAPGEN_SETMAP_BASH,
JMAPGEN_SETMAP_VARIABLE,
JMAPGEN_SETMAP_OPTYPE_LINE = 100,
Expand All @@ -132,13 +133,15 @@ enum jmapgen_setmap_op {
JMAPGEN_SETMAP_LINE_RADIATION,
JMAPGEN_SETMAP_LINE_TRAP_REMOVE,
JMAPGEN_SETMAP_LINE_ITEM_REMOVE,
JMAPGEN_SETMAP_LINE_FIELD_REMOVE,
JMAPGEN_SETMAP_OPTYPE_SQUARE = 200,
JMAPGEN_SETMAP_SQUARE_TER,
JMAPGEN_SETMAP_SQUARE_FURN,
JMAPGEN_SETMAP_SQUARE_TRAP,
JMAPGEN_SETMAP_SQUARE_RADIATION,
JMAPGEN_SETMAP_SQUARE_TRAP_REMOVE,
JMAPGEN_SETMAP_SQUARE_ITEM_REMOVE
JMAPGEN_SETMAP_SQUARE_ITEM_REMOVE,
JMAPGEN_SETMAP_SQUARE_FIELD_REMOVE
};

struct jmapgen_setmap {
Expand Down
6 changes: 6 additions & 0 deletions src/mapgen_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3246,6 +3246,12 @@ void madd_field( map *m, const point &p, field_type_id type, int intensity )
m->add_field( actual_location, type, intensity, 0_turns );
}

void mremove_fields( map *m, const point &p )
{
tripoint actual_location( p, m->get_abs_sub().z() );
m->clear_fields( actual_location );
}

void resolve_regional_terrain_and_furniture( const mapgendata &dat )
{
for( const tripoint &p : dat.m.points_on_zlevel() ) {
Expand Down
1 change: 1 addition & 0 deletions src/mapgen_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void mapgen_ravine_edge( mapgendata &dat );
void mremove_trap( map *m, const point &, trap_id type );
void mtrap_set( map *m, const point &, trap_id type );
void madd_field( map *m, const point &, field_type_id type, int intensity );
void mremove_fields( map *m, const point & );

mapgen_update_func add_mapgen_update_func( const JsonObject &jo, bool &defer );
bool run_mapgen_update_func( const update_mapgen_id &, const tripoint_abs_omt &omt_pos,
Expand Down

0 comments on commit 5c9be55

Please sign in to comment.