Skip to content

Commit

Permalink
feat(port): Allow custom surround monster groups in scenarios (#4665)
Browse files Browse the repository at this point in the history
* Allow custom surround monster groups in scenarios

dda port CleverRaven/Cataclysm-DDA#47990

* style(autofix.ci): automated formatting

* Update mods

* smol idea

* docs time bay-bee

* style(autofix.ci): automated formatting

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Chaosvolt <[email protected]>
  • Loading branch information
3 people authored May 18, 2024
1 parent de968c9 commit 1fc96eb
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 13 deletions.
39 changes: 39 additions & 0 deletions data/json/monstergroups/misc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,45 @@
"is_safe": true,
"default": "mon_null"
},
{
"type": "monstergroup",
"name": "GROUP_BLACK_ROAD",
"default": "mon_zombie",
"monsters": [
{ "monster": "mon_zombie", "freq": 1, "cost_multiplier": 7, "pack_size": [ 5, 20 ] },
{ "monster": "mon_zombie", "freq": 1, "cost_multiplier": 13, "pack_size": [ 15, 40 ] },
{ "monster": "mon_zombie", "freq": 1, "cost_multiplier": 20, "pack_size": [ 25, 60 ] },
{ "monster": "mon_zombie", "freq": 75, "cost_multiplier": 0 },
{ "monster": "mon_zombie_fat", "freq": 75, "cost_multiplier": 2 },
{ "monster": "mon_zombie_fat", "freq": 3, "cost_multiplier": 7, "pack_size": [ 3, 5 ] },
{ "monster": "mon_zombie_tough", "freq": 75, "cost_multiplier": 3 },
{ "monster": "mon_zombie_child", "freq": 75, "cost_multiplier": 1 },
{ "monster": "mon_zombie_rot", "freq": 50, "cost_multiplier": 3 },
{ "monster": "mon_zombie_crawler", "freq": 25, "cost_multiplier": 3 },
{ "monster": "mon_zombie_dog", "freq": 20, "cost_multiplier": 2 },
{ "monster": "mon_zombie_dog", "freq": 1, "cost_multiplier": 4, "pack_size": [ 3, 5 ] },
{ "monster": "mon_zombie_dog", "freq": 1, "cost_multiplier": 16, "pack_size": [ 5, 8 ] },
{ "monster": "mon_zombie_dog", "freq": 1, "cost_multiplier": 24, "pack_size": [ 8, 12 ] },
{ "monster": "mon_dog_zombie_cop", "freq": 5, "cost_multiplier": 4 },
{ "monster": "mon_dog_zombie_rot", "freq": 5, "cost_multiplier": 5 },
{ "monster": "mon_zombie_soldier", "freq": 10, "cost_multiplier": 2 },
{ "monster": "mon_zombie_cop", "freq": 20, "cost_multiplier": 3 },
{ "monster": "mon_zombie_swat", "freq": 10, "cost_multiplier": 3 },
{ "monster": "mon_zombie_hazmat", "freq": 10, "cost_multiplier": 3 },
{ "monster": "mon_zombie_fireman", "freq": 10, "cost_multiplier": 2 },
{ "monster": "mon_zombie_swimmer", "freq": 10, "cost_multiplier": 5 },
{ "monster": "mon_zombie_static", "freq": 10, "cost_multiplier": 5 },
{ "monster": "mon_zombie_survivor", "freq": 1, "cost_multiplier": 25 },
{ "monster": "mon_zombie_survivor_elite", "freq": 1, "cost_multiplier": 25, "starts": 1440 },
{ "monster": "mon_beekeeper", "freq": 1, "cost_multiplier": 5 },
{ "monster": "mon_zombie_technician", "freq": 1, "cost_multiplier": 12 },
{ "monster": "mon_zombie_runner", "freq": 20, "cost_multiplier": 5, "pack_size": [ 1, 4 ] },
{ "monster": "mon_feral_human_pipe", "freq": 4, "cost_multiplier": 1, "pack_size": [ 2, 3 ] },
{ "monster": "mon_feral_human_crowbar", "freq": 4, "cost_multiplier": 1, "pack_size": [ 2, 3 ] },
{ "monster": "mon_feral_human_axe", "freq": 2, "cost_multiplier": 2, "pack_size": [ 1, 2 ] },
{ "monster": "mon_zombie_brainless", "freq": 65, "cost_multiplier": 1 }
]
},
{
"type": "monstergroup",
"name": "GROUP_CHUD",
Expand Down
9 changes: 6 additions & 3 deletions data/json/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"description": "Whether due to stubbornness, ignorance, or just plain bad luck, you missed the evacuation, and are stuck in a large building full of the risen dead.",
"allowed_locs": [ "sloc_mall_loading_area", "sloc_mall_food_court", "sloc_apartments_rooftop", "sloc_hospital", "sloc_bastion_fort" ],
"start_name": "In Large Building",
"flags": [ "SUR_START", "CITY_START", "LONE_START" ]
"surround_groups": [ [ "GROUP_BLACK_ROAD", 70.0 ] ],
"flags": [ "CITY_START", "LONE_START" ]
},
{
"type": "scenario",
Expand All @@ -65,7 +66,8 @@
"sloc_town_hall"
],
"start_name": "In Town",
"flags": [ "SUR_START", "CITY_START", "LONE_START" ]
"surround_groups": [ [ "GROUP_BLACK_ROAD", 70.0 ] ],
"flags": [ "CITY_START", "LONE_START" ]
},
{
"type": "scenario",
Expand Down Expand Up @@ -332,7 +334,8 @@
"sloc_bastion_fort"
],
"start_name": "Outside Town",
"flags": [ "SUR_START", "WIN_START", "LONE_START" ],
"surround_groups": [ [ "GROUP_BLACK_ROAD", 70.0 ] ],
"flags": [ "WIN_START", "LONE_START" ],
"add_professions": true,
"professions": [
"sheltered_survivor",
Expand Down
3 changes: 2 additions & 1 deletion data/mods/Magiclysm/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"type": "scenario",
"id": "lost_faith",
"name": "Lost Faith",
"flags": [ "SUR_START", "LONE_START" ],
"surround_groups": [ [ "GROUP_CHURCH_ZOMBIE", 70.0 ] ],
"flags": [ "LONE_START" ],
"points": 2,
"description": "You've been preaching your faith for a long time, but the recent events have begun to make you doubt it. Wandering in your temple, you just found books that may restore your faith or shatter it completely.",
"start_name": "Church",
Expand Down
5 changes: 3 additions & 2 deletions data/mods/more_classes_scenarios/cs_scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"specops"
],
"start_name": "Fema Camp",
"flags": [ "HELI_CRASH", "SUR_START", "FIRE_START", "INFECTED", "CHALLENGE" ]
"surround_groups": [ [ "GROUP_BLACK_ROAD", 70.0 ] ],
"flags": [ "HELI_CRASH", "FIRE_START", "INFECTED", "CHALLENGE" ]
},
{
"type": "scenario",
Expand All @@ -31,7 +32,7 @@
"allowed_locs": [ "sloc_mansion", "sloc_mansion_entrance" ],
"professions": [ "maid" ],
"start_name": "Mansion",
"flags": [ "SUR_START" ]
"surround_groups": [ [ "GROUP_BLACK_ROAD", 70.0 ] ]
},
{
"type": "scenario",
Expand Down
1 change: 0 additions & 1 deletion doc/src/content/docs/en/mod/json/reference/json_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,6 @@ These branches are also the valid entries for the categories of `dreams` in `dre
- `LONE_START` If starting NPC spawn option is switched to "Scenario-based", this scenario won't
spawn a fellow NPC on game start.
- `SCEN_ONLY` Profession can be chosen only as part of the appropriate scenario.
- `SUR_START` Surrounded start, zombies outside the starting location.

#### Season Flags

Expand Down
14 changes: 14 additions & 0 deletions doc/src/content/docs/en/mod/json/reference/scenarios.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ Example for mods:
}
```

## `surround_groups`

(optional, array with group and density number)

This replaces the `SUR_START` flag for scenarios, specifies groups of monsters which spawn in the
area surrounding the scenario's staritng location.

```json
"surround_groups": [ [ "GROUP_BLACK_ROAD", 70.0 ] ],
```

The string defines the ID of which monstergroup will be spawned in the surrounding area, while the
number is the density of spawns. 70.0 replicates the value of the original `SUR_START` behavior.

## `flags`

(optional, array of strings)
Expand Down
3 changes: 2 additions & 1 deletion doc/src/content/docs/en/mod/json/tutorial/modding.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ Below you will find the JSON definition for the game's built-in `Large Building`
"hospital_9"
],
"start_name": "In Large Building",
"flags": ["SUR_START", "CITY_START", "LONE_START"]
"surround_groups": [["GROUP_BLACK_ROAD", 70.0]],
"flags": ["CITY_START", "LONE_START"]
}
]
```
Expand Down
17 changes: 12 additions & 5 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,19 @@ bool game::start_game()
}
//Load NPCs. Set nearby npcs to active.
load_npcs();
// Spawn the monsters
const bool spawn_near =
get_option<bool>( "BLACK_ROAD" ) || g->scen->has_flag( "SUR_START" );
// Surrounded start ones

// Spawn the monsters for `Surrounded` starting scenarios
std::vector<std::pair<mongroup_id, float>> surround_groups = get_scenario()->surround_groups();
const bool surrounded_start_scenario = !surround_groups.empty();
const bool surrounded_start_options = get_option<bool>( "BLACK_ROAD" );
if( surrounded_start_options && !surrounded_start_scenario ) {
surround_groups.emplace_back( mongroup_id( "GROUP_BLACK_ROAD" ), 70.0f );
}
const bool spawn_near = surrounded_start_options || surrounded_start_scenario;
if( spawn_near ) {
start_loc.surround_with_monsters( omtstart, mongroup_id( "GROUP_ZOMBIE" ), 70 );
for( const std::pair<mongroup_id, float> &sg : surround_groups ) {
start_loc.surround_with_monsters( omtstart, sg.first, sg.second );
}
}

m.spawn_monsters( !spawn_near ); // Static monsters
Expand Down
8 changes: 8 additions & 0 deletions src/scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ void scenario::load( const JsonObject &jo, const std::string & )
if( jo.has_string( "vehicle" ) ) {
_starting_vehicle = vproto_id( jo.get_string( "vehicle" ) );
}

for( JsonArray ja : jo.get_array( "surround_groups" ) ) {
_surround_groups.emplace_back( mongroup_id( ja.get_string( 0 ) ), ja.get_float( 1 ) );
}
}

const scenario *scenario::generic()
Expand Down Expand Up @@ -462,4 +466,8 @@ const std::vector<mission_type_id> &scenario::missions() const
{
return _missions;
}
const std::vector<std::pair<mongroup_id, float>> &scenario::surround_groups() const
{
return _surround_groups;
}
// vim:ts=4:sw=4:et:tw=0:fdm=marker:
3 changes: 3 additions & 0 deletions src/scenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class scenario
void load( const JsonObject &jo, const std::string &src );
bool scenario_traits_conflict_with_profession_traits( const profession &p ) const;

std::vector<std::pair<mongroup_id, float>> _surround_groups;

public:
//these three aren't meant for external use, but had to be made public regardless
scenario();
Expand Down Expand Up @@ -113,6 +115,7 @@ class scenario

const std::vector<mission_type_id> &missions() const;

const std::vector<std::pair<mongroup_id, float>> &surround_groups() const;
};

struct scen_blacklist {
Expand Down

0 comments on commit 1fc96eb

Please sign in to comment.