@@ -181,7 +181,12 @@ static auto thing_drop_item(Gamep g, Levelsp v, Levelp l, Thingp item, Thingp dr
181181 //
182182 // Add to the inventory.
183183 //
184- if (! thing_inventory_add (g, v, l, item, carrier)) {
184+ if (thing_inventory_add (g, v, l, item, carrier)) {
185+ //
186+ // Success
187+ //
188+ (void ) thing_on_carry_success (g, v, l, item, carrier);
189+ } else {
185190 //
186191 // Possibly out of slots
187192 //
@@ -210,7 +215,15 @@ static auto thing_drop_item(Gamep g, Levelsp v, Levelp l, Thingp item, Thingp dr
210215 //
211216 // Remove from the inventory.
212217 //
213- if (! thing_inventory_remove (g, v, l, item, carrier)) {
218+ if (thing_inventory_remove (g, v, l, item, carrier)) {
219+ //
220+ // Success
221+ //
222+ (void ) thing_on_carry_success (g, v, l, item, carrier);
223+ } else {
224+ //
225+ // Remove failed
226+ //
214227 item->_is_carried = old_value;
215228
216229 auto s = to_string (g, v, l, item);
@@ -296,6 +309,68 @@ void thing_on_drop_request_set(Tpp tp, thing_on_drop_request_t callback)
296309 return tp->on_drop_request (g, v, l, me, dropper);
297310}
298311
312+ void thing_on_carry_success_set (Tpp tp, thing_on_carry_success_t callback)
313+ {
314+ TRACE ();
315+ if (tp == nullptr ) [[unlikely]] {
316+ ERR (" no thing template pointer" );
317+ return ;
318+ }
319+ tp->on_carry_success = callback;
320+ }
321+
322+ [[nodiscard]] auto thing_on_carry_success (Gamep g, Levelsp v, Levelp l, Thingp me, Thingp carrier) -> bool
323+ {
324+ TRACE ();
325+ auto *tp = thing_tp (me);
326+ if (tp == nullptr ) [[unlikely]] {
327+ ERR (" no thing template pointer" );
328+ return false ;
329+ }
330+ if (tp->on_carry_success == nullptr ) {
331+ //
332+ // Assume success
333+ //
334+ return true ;
335+ }
336+ if (! thing_is_player (carrier) && ! thing_is_monst (carrier)) {
337+ thing_err (carrier, " unexpected thing for %s" , __FUNCTION__);
338+ return false ;
339+ }
340+ return tp->on_carry_success (g, v, l, me, carrier);
341+ }
342+
343+ void thing_on_drop_success_set (Tpp tp, thing_on_drop_success_t callback)
344+ {
345+ TRACE ();
346+ if (tp == nullptr ) [[unlikely]] {
347+ ERR (" no thing template pointer" );
348+ return ;
349+ }
350+ tp->on_drop_success = callback;
351+ }
352+
353+ [[nodiscard]] auto thing_on_drop_success (Gamep g, Levelsp v, Levelp l, Thingp me, Thingp dropper) -> bool
354+ {
355+ TRACE ();
356+ auto *tp = thing_tp (me);
357+ if (tp == nullptr ) [[unlikely]] {
358+ ERR (" no thing template pointer" );
359+ return false ;
360+ }
361+ if (tp->on_drop_success == nullptr ) {
362+ //
363+ // Assume success
364+ //
365+ return true ;
366+ }
367+ if (! thing_is_player (dropper) && ! thing_is_monst (dropper)) {
368+ thing_err (dropper, " unexpected thing for %s" , __FUNCTION__);
369+ return false ;
370+ }
371+ return tp->on_drop_success (g, v, l, me, dropper);
372+ }
373+
299374[[nodiscard]] auto thing_carry (Gamep g, Levelsp v, Levelp l, Thingp me, Thingp item, ThingEvent &e) -> bool
300375{
301376 TRACE ();
0 commit comments