Skip to content

Commit

Permalink
Add json controlled weather effects (#41905)
Browse files Browse the repository at this point in the history
* Move more weather pieces into weather datum and json
* Move existing effects into new framework
* Add radiation, health, effects, and spawns
* Add translations, damage and target parts
* Add traits to weather effects
  • Loading branch information
Ramza13 authored Jul 14, 2020
1 parent 0a6dc28 commit 3cb4015
Show file tree
Hide file tree
Showing 8 changed files with 451 additions and 153 deletions.
51 changes: 45 additions & 6 deletions data/json/weather_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,14 @@
"precip": "heavy",
"rains": true,
"acidic": false,
"effects": [ { "name": "thunder", "intensity": 50 } ],
"effects": [
{
"one_in_chance": 50,
"must_be_outside": false,
"sound_message": "You hear a distant rumble of thunder.",
"sound_effect": "thunder_far"
}
],
"tiles_animation": "weather_rain_drop",
"weather_animation": { "factor": 0.02, "color": "c_light_blue", "glyph": "." },
"sound_category": "thunder",
Expand All @@ -174,7 +181,21 @@
"precip": "heavy",
"rains": true,
"acidic": false,
"effects": [ { "name": "thunder", "intensity": 50 }, { "name": "lightning", "intensity": 600 } ],
"effects": [
{
"one_in_chance": 50,
"must_be_outside": false,
"sound_message": "You hear a distant rumble of thunder.",
"sound_effect": "thunder_far"
},
{
"one_in_chance": 600,
"must_be_outside": false,
"message": "A flash of lightning illuminates your surroundings!.",
"sound_effect": "thunder_near",
"lightning": true
}
],
"tiles_animation": "weather_rain_drop",
"weather_animation": { "factor": 0.04, "color": "c_light_blue", "glyph": "," },
"sound_category": "thunder",
Expand All @@ -196,7 +217,16 @@
"precip": "light",
"rains": true,
"acidic": true,
"effects": [ { "name": "light_acid", "intensity": 180 } ],
"effects": [
{
"time_between": "3 minutes",
"must_be_outside": true,
"message": "The acid rain stings, but is mostly harmless for now…",
"rain_proof": true,
"pain_max": 10,
"pain": 1
}
],
"tiles_animation": "weather_acid_drop",
"weather_animation": { "factor": 0.01, "color": "c_light_green", "glyph": "." },
"sound_category": "drizzle",
Expand All @@ -218,7 +248,16 @@
"precip": "heavy",
"rains": true,
"acidic": true,
"effects": [ { "name": "acid", "intensity": 2 } ],
"effects": [
{
"time_between": "2 seconds",
"must_be_outside": true,
"message": "The acid rain burns!",
"rain_proof": true,
"pain_max": 100,
"pain": 3
}
],
"tiles_animation": "weather_acid_drop",
"weather_animation": { "factor": 0.02, "color": "c_light_green", "glyph": "," },
"sound_category": "rainy",
Expand Down Expand Up @@ -261,7 +300,7 @@
"precip": "heavy",
"rains": false,
"acidic": false,
"effects": [ { "name": "wet", "intensity": 10 } ],
"effects": [ { "must_be_outside": true, "wet": 10 } ],
"tiles_animation": "weather_snowflake",
"weather_animation": { "factor": 0.02, "color": "c_white", "glyph": "," },
"sound_category": "snow",
Expand All @@ -283,7 +322,7 @@
"precip": "heavy",
"rains": false,
"acidic": false,
"effects": [ { "name": "wet", "intensity": 40 } ],
"effects": [ { "must_be_outside": true, "wet": 40 } ],
"tiles_animation": "weather_snowflake",
"weather_animation": { "factor": 0.04, "color": "c_white", "glyph": "*" },
"sound_category": "snowstorm",
Expand Down
108 changes: 99 additions & 9 deletions doc/WEATHER_TYPE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ Each weather type is a type of weather that occurs, its effects and what causes
snowstorm and snow. |
| `sun_intensity` | Strength of the sun. Valid values are: none, light, normal, and high |
| `weather_animation` | Optional, Information controlling weather animations. Members: factor, color and glyph |
| `effects` | String, int pair array for the effects the weather has. At present wet, thunder, lightning, light_acid, and acid are supported. |
`wet` | wets player by int amount
`thunder` | thunder sound with chance 1 in int
`lightening` | 1 in int chance of sound plus message and possible super charging electric fields
`light_acid` | causes pain unless waterproof
`acid_rain` | causes more pain unless waterproof

| `effects` | Array for the effects the weather has. Descibed in detail below
| `requirements` | Optional, is what determines what weather it is. All members are optional.
When checking what weather it is it loops through the entries in order and uses the last one to succeed. |

Expand Down Expand Up @@ -67,11 +61,107 @@ Each weather type is a type of weather that occurs, its effects and what causes
"precip": "heavy",
"rains": true,
"acidic": false,
"effects": [ { "name": "thunder", "intensity": 50 }, { "name": "lightning", "intensity": 600 } ],
"effects": [
{
"one_in_chance": 50,
"must_be_outside":false,
"sound_message": "You hear a distant rumble of thunder.",
"sound_effect": "thunder_far"
},
{
"one_in_chance": 600,
"must_be_outside":false,
"message": "A flash of lightning illuminates your surroundings!.",
"sound_effect": "thunder_near",
"lightning":true
}
],
"tiles_animation": "weather_rain_drop",
"weather_animation": { "factor": 0.04, "color": "c_light_blue", "glyph": "," },
"sound_category": "thunder",
"sun_intensity": "none",
"requirements": { "pressure_max": 990, "required_weathers": [ "thunder" ] }
}
},
```
### Weather_effects

Things that weather can cause to happen.

##Fields

| Identifier | Description |
| ------------------------------ | --------------------------------------------------------------------- |
| `message` | Optional: Message displayed when this effect happens. |
| `sound_message` | Optional: Message describing what you hear, will not display if deaf |
| `sound_effect` | Optional: Name of sound effect to play |
| `sound_message` | Optional: Message describing what you hear for this, will not display if deaf. |
| `must_be_outside` | Whether the effect only happens while you are outside. |
| `one_in_chance` | Optional: The chance of the event occuring is 1 in this value, if blank will always happen. |
| `time_between` | Optional: The time between instances of this effect occuring. If both this and one_in_chance are set will only happen when both are true. |
| `lightning` | Optional: Causes the world be bright at night and supercharge monster electric fields. |
| `rain_proof` | Optional: If rainproof, resistant gear will help against this |
| `pain_max` | Optional: If there is a threshold of pain at which this will stop happening. |
| `pain` | Optional: How much pain this causes. |
| `wet` | Optional: How much wet this causes. |
| `radiation` | Optional: How much radiation this causes. |
| `healthy` | Optional: How much healthy this adds or removes. |
| `effect_id` | Optional: String id of an effect to add. |
| `effect_duration` | Optional: How long the above effect will be added for, defaults to 1 second. |
| `target_part` | Optional: Bodypart that above effect or damage are applied to, if blank affects whole body. |
| `damage` | Optional: Hp bashing damage applied. |
| `spawns` | Optional: Array of spawns to cause. If spawns are selected but are unable to spawn the effect is cancelled. |
| `fields` | Optional: Array of fields to cause. Elements are discussed below |
optional( weather_effect_jo, was_loaded, "", effect.lightning, false );
### Example

```json
{
"must_be_outside":true,
"radiation":10,
"healthy":1,
"message":"Suddenly a something",
"add_effect":"bite",
"effect_duration":"10 minutes",
"target_part": "arm_l",
"damage":5,
"spawns":
[{
"max_radius":10,
"min_radius":10,
"target":"mon_zombie_survivor_elite",
"hallucination_count":1,
"real_count":0
}]
```
### spawn_type

How many and what spawns

##Fields

| Identifier | Description |
| ------------------------------ | --------------------------------------------------------------------- |
| `max_radius` | Optional: The furthest away a spawn will happen. |
| `min_radius` | Optional: The closest a spawn will happen. |
| `hallucination_count` | Optional: Number of hallucinations of the target to spawn. |
| `real_count` | Optional: Number of real copies to spawn. |
| `target` | Optional: Monster id of target to spawn. If left blank a nearby monster will be used. |
| `target_range` | Optional: If target is left blank how far away to look for something to copy. |

### fields

Fields to create what kind and where

##Fields

| Identifier | Description |
| ------------------------------ | --------------------------------------------------------------------- |
| `type` | The string id of the field. |
| `intensity` | Intensity of the field. |
| `age` | Age of the field. |
| `outdoor_only` | Optional: Defaults to true. If true field will only spawn outdoors. |
| `radius` | Optional: Radius around player the effect will spread, defaults to everywhere. |



30 changes: 29 additions & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5133,6 +5133,25 @@ void game::clear_zombies()
critter_tracker->clear();
}

bool game::find_nearby_spawn_point( const Character &target, const mtype_id &mt, int min_radius,
int max_radius, tripoint &point )
{
tripoint target_point;
//find a legal outdoor place to spawn based on the specified radius,
//we just try a bunch of random points and use the first one that works, it none do then no spawn
for( int attempts = 0; attempts < 15; attempts++ ) {
target_point = target.pos() + tripoint( rng( -max_radius, max_radius ),
rng( -max_radius, max_radius ), 0 );
if( can_place_monster( mt->id, target_point ) &&
get_map().is_outside( target_point ) &&
rl_dist( target_point, get_player_character().pos() ) > min_radius ) {
point = target_point;
return true;
}
}
return false;
}

/**
* Attempts to spawn a hallucination at given location.
* Returns false if the hallucination couldn't be spawned for whatever reason, such as
Expand All @@ -5155,7 +5174,16 @@ bool game::spawn_hallucination( const tripoint &p )
}
}

const mtype_id &mt = MonsterGenerator::generator().get_valid_hallucination();
return spawn_hallucination( p, MonsterGenerator::generator().get_valid_hallucination() );
}
/**
* Attempts to spawn a hallucination at given location.
* Returns false if the hallucination couldn't be spawned for whatever reason, such as
* a monster already in the target square.
* @return Whether or not a hallucination was successfully spawned.
*/
bool game::spawn_hallucination( const tripoint &p, const mtype_id &mt )
{
const shared_ptr_fast<monster> phantasm = make_shared_fast<monster>( mt );
phantasm->hallucination = true;
phantasm->spawn( p );
Expand Down
5 changes: 5 additions & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ class game
void clear_zombies();
/** Spawns a hallucination at a determined position. */
bool spawn_hallucination( const tripoint &p );
/** Spawns a hallucination at a determined position of a given monster. */
bool spawn_hallucination( const tripoint &p, const mtype_id &mt );
/** Finds somewhere to spawn a monster. */
bool find_nearby_spawn_point( const Character &target, const mtype_id &mt, int min_radius,
int max_radius, tripoint &point );
/** Swaps positions of two creatures */
bool swap_critters( Creature &, Creature & );

Expand Down
Loading

0 comments on commit 3cb4015

Please sign in to comment.