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

Make thrown glass items drop glass shards when shattered #48727

Merged
Merged
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
16 changes: 16 additions & 0 deletions src/ballistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "explosion.h"
#include "game.h"
#include "item.h"
#include "itype.h"
#include "line.h"
#include "map.h"
#include "messages.h"
Expand Down Expand Up @@ -62,6 +63,21 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack )
// TODO: Wine glass breaking vs. entire sheet of glass breaking
sounds::sound( pt, 16, sounds::sound_t::combat, _( "glass breaking!" ), false, "bullet_hit",
"hit_glass" );

const units::mass shard_mass = itype_id( "glass_shard" )->weight;
const int max_nb_of_shards = floor( to_gram( drop_item.type->weight ) / to_gram( shard_mass ) );
//between half and max_nb_of_shards-1 will be usable
const int nb_of_dropped_shard = std::max( 0, rng( max_nb_of_shards / 2, max_nb_of_shards - 1 ) );
//feel free to remove this msg_debug
/*add_msg_debug( "Shattered %s dropped %i shards out of a max of %i, based on mass %i g",
drop_item.tname(), nb_of_dropped_shard, max_nb_of_shards - 1, to_gram( drop_item.type->weight ) );*/

for( int i = 0; i < nb_of_dropped_shard; ++i ) {
item shard( "glass_shard" );
//actual dropping of shards
get_map().add_item_or_charges( pt, shard );
}

return;
}

Expand Down