+void
+deliver_obj_to_mon(mtmp, cnt, deliverflags)
+int cnt;
+struct monst *mtmp;
+unsigned long deliverflags;
+{
+ struct obj *otmp, *otmp2;
+ int where, maxobj = 1;
+ boolean at_crime_scene = In_mines(&u.uz);
+
+ if ((deliverflags & DF_RANDOM) && cnt > 1)
+ maxobj = rnd(cnt);
+ else if (deliverflags & DF_ALL)
+ maxobj = 0;
+ else
+ maxobj = 1;
+
+ cnt = 0;
+ for (otmp = migrating_objs; otmp; otmp = otmp2) {
+ otmp2 = otmp->nobj;
+ where = (int) (otmp->owornmask & 0x7fffL); /* destination code */
+ if ((where & MIGR_TO_SPECIES) == 0)
+ continue;
+
+ if ((mtmp->data->mflags2 & otmp->corpsenm) != 0) {
+ obj_extract_self(otmp);
+ otmp->owornmask = 0L;
+ otmp->ox = otmp->oy = 0;
+
+ /* special treatment for orcs and their kind */
+ if ((otmp->corpsenm & M2_ORC) != 0 && has_oname(otmp)) {
+ if (!has_mname(mtmp)) {
+ if (at_crime_scene || !rn2(2))
+ mtmp = christen_orc(mtmp,
+ at_crime_scene ? ONAME(otmp)
+ : (char *) 0,
+ /* bought the stolen goods */
+ " the Fence");
+ }
+ free_oname(otmp);
+ }
+ otmp->corpsenm = 0;
+ (void) add_to_minv(mtmp, otmp);
+ cnt++;
+ if (maxobj && cnt >= maxobj)
+ break;
+ /* getting here implies DF_ALL */
+ }
+ }
+}
+