Skip to content

Commit

Permalink
Jsonize species descriptions (#36906)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhilkinSerg authored and kevingranade committed Jan 12, 2020
1 parent 2df9b66 commit d2ba189
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
26 changes: 23 additions & 3 deletions data/json/species.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,106 +2,126 @@
{
"type": "SPECIES",
"id": "MAMMAL",
"description": "a mammal",
"fear_triggers": [ "HURT", "FIRE", "FRIEND_DIED" ]
},
{
"type": "SPECIES",
"id": "AMPHIBIAN",
"description": "an amphibian",
"fear_triggers": [ "HURT", "FIRE" ]
},
{
"type": "SPECIES",
"id": "BIRD",
"description": "a bird",
"fear_triggers": [ "HURT", "SOUND" ]
},
{
"type": "SPECIES",
"id": "REPTILE",
"description": "a reptile",
"fear_triggers": [ "HURT", "FIRE" ]
},
{
"type": "SPECIES",
"id": "FISH",
"description": "a fish",
"fear_triggers": [ "HURT", "FRIEND_ATTACKED" ]
},
{
"type": "SPECIES",
"id": "MUTANT",
"description": "a mutant",
"fear_triggers": [ "FIRE" ]
},
{
"type": "SPECIES",
"id": "NETHER",
"description": "a nether creature",
"fear_triggers": [ "HURT" ]
},
{
"type": "SPECIES",
"id": "BLOB",
"description": "a blob",
"footsteps": "plop."
},
{
"type": "SPECIES",
"id": "FUNGUS",
"description": "a fungus",
"fear_triggers": [ "HURT", "FIRE" ]
},
{
"type": "SPECIES",
"id": "LEECH_PLANT",
"description": "a leech plant",
"fear_triggers": [ "HURT", "FIRE" ]
},
{
"type": "SPECIES",
"id": "INSECT",
"description": "an insect",
"anger_triggers": [ "FRIEND_DIED" ],
"fear_triggers": [ "HURT", "FIRE" ]
},
{
"type": "SPECIES",
"id": "SPIDER",
"description": "a spider",
"anger_triggers": [ "FRIEND_DIED" ],
"fear_triggers": [ "HURT", "FIRE" ]
},
{
"type": "SPECIES",
"id": "PLANT",
"description": "a plant",
"fear_triggers": [ "HURT", "FIRE" ]
},
{
"type": "SPECIES",
"id": "MOLLUSK",
"description": "a mollusk",
"fear_triggers": [ "HURT", "FIRE" ]
},
{
"type": "SPECIES",
"id": "WORM",
"description": "a worm",
"footsteps": "rustle.",
"fear_triggers": [ "HURT" ]
},
{
"type": "SPECIES",
"id": "ZOMBIE",
"description": "a zombie",
"footsteps": "shuffling."
},
{
"type": "SPECIES",
"id": "ROBOT",
"description": "a robot",
"footsteps": "mechanical whirring."
},
{
"type": "SPECIES",
"id": "HORROR"
"id": "HORROR",
"description": "a horror"
},
{
"type": "SPECIES",
"id": "ABERRATION"
"id": "ABERRATION",
"description": "an aberration"
},
{
"type": "SPECIES",
"id": "HALLUCINATION"
},
{
"type": "SPECIES",
"id": "HUMAN"
"id": "HUMAN",
"description": "a human"
},
{
"type": "SPECIES",
Expand Down
14 changes: 1 addition & 13 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,22 +682,10 @@ std::string monster::extended_description() const
ss += string_format( _( "It is %s in size." ),
size_names.at( get_size() ) ) + "\n";

std::vector<std::string> types;
std::vector<std::string> types = type->species_descriptions();
if( type->has_flag( MF_ANIMAL ) ) {
types.emplace_back( _( "an animal" ) );
}
if( type->in_species( ZOMBIE ) ) {
types.emplace_back( _( "a zombie" ) );
}
if( type->in_species( FUNGUS ) ) {
types.emplace_back( _( "a fungus" ) );
}
if( type->in_species( INSECT ) ) {
types.emplace_back( _( "an insect" ) );
}
if( type->in_species( ABERRATION ) ) {
types.emplace_back( _( "an aberration" ) );
}
if( !types.empty() ) {
ss += string_format( _( "It is %s." ),
enumerate_as_string( types ) ) + "\n";
Expand Down
1 change: 1 addition & 0 deletions src/monstergenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@ void MonsterGenerator::load_species( const JsonObject &jo, const std::string &sr

void species_type::load( const JsonObject &jo, const std::string & )
{
optional( jo, was_loaded, "description", description );
optional( jo, was_loaded, "footsteps", footsteps, "footsteps." );
footsteps = _( footsteps );
const auto flag_reader = enum_flags_reader<m_flag> { "monster flag" };
Expand Down
1 change: 1 addition & 0 deletions src/monstergenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ using mon_action_defend = void ( * )( monster &, Creature *, dealt_projectile_at
struct species_type {
species_id id;
bool was_loaded = false;
translation description;
std::string footsteps;
enum_bitset<m_flag> flags;
enum_bitset<mon_trigger> anger;
Expand Down
10 changes: 10 additions & 0 deletions src/mtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ bool mtype::in_species( const species_type &spec ) const
{
return species_ptrs.count( &spec ) > 0;
}
std::vector<std::string> mtype::species_descriptions() const
{
std::vector<std::string> ret;
for( const species_id &s : species ) {
if( !s->description.empty() ) {
ret.emplace_back( s->description.translated() );
}
}
return ret;
}

bool mtype::same_species( const mtype &other ) const
{
Expand Down
1 change: 1 addition & 0 deletions src/mtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ struct mtype {
bool in_category( const std::string &category ) const;
bool in_species( const species_id &spec ) const;
bool in_species( const species_type &spec ) const;
std::vector<std::string> species_descriptions() const;
//Used for corpses.
field_type_id bloodType() const;
field_type_id gibType() const;
Expand Down

0 comments on commit d2ba189

Please sign in to comment.