From fe6e9d1d1f005644675a9d2caf9a1dc1b23f402a Mon Sep 17 00:00:00 2001 From: zeropol Date: Sat, 1 May 2021 22:09:56 +0200 Subject: [PATCH 1/2] Make thrown glass items drop glass shard when thrown Because some of the shards should be usable. The item has to weight at least 2 times a glass shard. There is some randomness involved. Does NOT affect smashed items. --- src/ballistics.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/ballistics.cpp b/src/ballistics.cpp index ff3ab4f987880..80480de9a5a5c 100644 --- a/src/ballistics.cpp +++ b/src/ballistics.cpp @@ -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" @@ -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; } From ccb816319153ef48c7e351f9a1c69f2920541fea Mon Sep 17 00:00:00 2001 From: zeropol Date: Sun, 2 May 2021 02:35:51 +0200 Subject: [PATCH 2/2] Comment not-that-useful msg_debug It is a shamy attempt to avoid string freeze. --- src/ballistics.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ballistics.cpp b/src/ballistics.cpp index 80480de9a5a5c..85d93b36a2185 100644 --- a/src/ballistics.cpp +++ b/src/ballistics.cpp @@ -69,8 +69,8 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack ) //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 ) ); + /*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" );