… | |
… | |
91 | find_best_object_match (object *pl, const char *params) |
91 | find_best_object_match (object *pl, const char *params) |
92 | { |
92 | { |
93 | return find_best_apply_object_match (pl, params, AP_TOGGLE); |
93 | return find_best_apply_object_match (pl, params, AP_TOGGLE); |
94 | } |
94 | } |
95 | |
95 | |
|
|
96 | static bool |
|
|
97 | can_split (object *pl, object *&op, sint32 nrof) |
|
|
98 | { |
|
|
99 | if (object *tmp = op->split (nrof)) |
|
|
100 | { |
|
|
101 | op = tmp; |
|
|
102 | return true; |
|
|
103 | } |
|
|
104 | else |
|
|
105 | { |
|
|
106 | new_draw_info_format (NDI_UNIQUE, 0, pl, "There are only %d %ss.", op->number_of (), &op->name); |
|
|
107 | return false; |
|
|
108 | } |
|
|
109 | } |
|
|
110 | |
96 | int |
111 | int |
97 | command_uskill (object *pl, char *params) |
112 | command_uskill (object *pl, char *params) |
98 | { |
113 | { |
99 | if (!params) |
114 | if (!params) |
100 | { |
115 | { |
… | |
… | |
208 | * not need to use split_ob and stuff. |
223 | * not need to use split_ob and stuff. |
209 | */ |
224 | */ |
210 | int |
225 | int |
211 | sack_can_hold (object *pl, object *sack, object *op, uint32 nrof) |
226 | sack_can_hold (object *pl, object *sack, object *op, uint32 nrof) |
212 | { |
227 | { |
213 | |
|
|
214 | if (!QUERY_FLAG (sack, FLAG_APPLIED)) |
228 | if (!QUERY_FLAG (sack, FLAG_APPLIED)) |
215 | { |
229 | { |
216 | new_draw_info_format (NDI_UNIQUE, 0, pl, "The %s is not active.", query_name (sack)); |
230 | new_draw_info_format (NDI_UNIQUE, 0, pl, "The %s is not active.", query_name (sack)); |
217 | return 0; |
231 | return 0; |
218 | } |
232 | } |
|
|
233 | |
219 | if (sack == op) |
234 | if (sack == op) |
220 | { |
235 | { |
221 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't put the %s into itself.", query_name (sack)); |
236 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't put the %s into itself.", query_name (sack)); |
222 | return 0; |
237 | return 0; |
223 | } |
238 | } |
|
|
239 | |
224 | if (sack->race && (sack->race != op->race || op->type == CONTAINER || (sack->stats.food && sack->stats.food != op->type))) |
240 | if (sack->race && (sack->race != op->race || op->type == CONTAINER || (sack->stats.food && sack->stats.food != op->type))) |
225 | { |
241 | { |
226 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You can put only %s into the %s.", &sack->race, query_name (sack)); |
242 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You can put only %s into the %s.", &sack->race, query_name (sack)); |
227 | return 0; |
243 | return 0; |
228 | } |
244 | } |
|
|
245 | |
229 | if (op->type == SPECIAL_KEY && sack->slaying && op->slaying) |
246 | if (op->type == SPECIAL_KEY && sack->slaying && op->slaying) |
230 | { |
247 | { |
231 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't put the key into %s.", query_name (sack)); |
248 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't put the key into %s.", query_name (sack)); |
232 | return 0; |
249 | return 0; |
233 | } |
250 | } |
|
|
251 | |
234 | if (sack->weight_limit && (sint32) (sack->carrying + (nrof ? nrof : 1) * |
252 | if (sack->weight_limit && (sint32) (sack->carrying + (nrof ? nrof : 1) * |
235 | (op->weight + (op->type == CONTAINER ? (op->carrying * op->stats.Str) : 0)) |
253 | (op->weight + (op->type == CONTAINER ? (op->carrying * op->stats.Str) : 0)) |
236 | * (100 - sack->stats.Str) / 100) > sack->weight_limit) |
254 | * (100 - sack->stats.Str) / 100) > sack->weight_limit) |
237 | { |
255 | { |
238 | new_draw_info_format (NDI_UNIQUE, 0, pl, "That won't fit in the %s!", query_name (sack)); |
256 | new_draw_info_format (NDI_UNIQUE, 0, pl, "That won't fit in the %s!", query_name (sack)); |
239 | return 0; |
257 | return 0; |
240 | } |
258 | } |
|
|
259 | |
241 | /* All other checks pass, must be OK */ |
260 | /* All other checks pass, must be OK */ |
242 | return 1; |
261 | return 1; |
243 | } |
262 | } |
244 | |
263 | |
245 | /* Pick up commands follow */ |
264 | /* Pick up commands follow */ |
… | |
… | |
252 | static void |
271 | static void |
253 | pick_up_object (object *pl, object *op, object *tmp, int nrof) |
272 | pick_up_object (object *pl, object *op, object *tmp, int nrof) |
254 | { |
273 | { |
255 | object *env = tmp->env; |
274 | object *env = tmp->env; |
256 | uint32 weight, effective_weight_limit; |
275 | uint32 weight, effective_weight_limit; |
257 | int tmp_nrof = tmp->nrof ? tmp->nrof : 1; |
276 | int tmp_nrof = tmp->number_of (); |
258 | |
277 | |
259 | /* IF the player is flying & trying to take the item out of a container |
278 | /* IF the player is flying & trying to take the item out of a container |
260 | * that is in his inventory, let him. tmp->env points to the container |
279 | * that is in his inventory, let him. tmp->env points to the container |
261 | * (sack, luggage, etc), tmp->env->env then points to the player (nested |
280 | * (sack, luggage, etc), tmp->env->env then points to the player (nested |
262 | * containers not allowed as of now) |
281 | * containers not allowed as of now) |
… | |
… | |
284 | { |
303 | { |
285 | new_draw_info (0, 0, pl, "That item is too heavy for you to pick up."); |
304 | new_draw_info (0, 0, pl, "That item is too heavy for you to pick up."); |
286 | return; |
305 | return; |
287 | } |
306 | } |
288 | |
307 | |
289 | if (nrof != tmp_nrof) |
308 | if (!can_split (pl, tmp, nrof)) |
290 | { |
|
|
291 | object *tmp2 = tmp; |
|
|
292 | |
|
|
293 | tmp = get_split_ob (tmp, nrof); |
|
|
294 | if (!tmp) |
|
|
295 | { |
|
|
296 | new_draw_info (NDI_UNIQUE, 0, pl, errmsg); |
|
|
297 | return; |
309 | return; |
298 | } |
|
|
299 | |
|
|
300 | /* Tell the client what happened to the rest of objects */ |
|
|
301 | if (pl->contr) |
|
|
302 | if (tmp2->destroyed ()) |
|
|
303 | esrv_del_item (pl->contr, tmp2->count); |
|
|
304 | else |
|
|
305 | esrv_update_item (UPD_NROF, pl, tmp2); |
|
|
306 | } |
|
|
307 | else |
|
|
308 | { |
|
|
309 | /* If the object is in a container, send a delete to the client. |
|
|
310 | * - we are moving all the items from the container to elsewhere, |
|
|
311 | * so it needs to be deleted. |
|
|
312 | */ |
|
|
313 | if (!QUERY_FLAG (tmp, FLAG_REMOVED)) |
|
|
314 | { |
|
|
315 | if (tmp->env && pl->type == PLAYER) |
|
|
316 | esrv_del_item (pl->contr, tmp->count); |
|
|
317 | |
|
|
318 | tmp->remove (); /* Unlink it */ |
|
|
319 | } |
|
|
320 | } |
|
|
321 | |
310 | |
322 | if (QUERY_FLAG (tmp, FLAG_UNPAID)) |
311 | if (QUERY_FLAG (tmp, FLAG_UNPAID)) |
323 | new_draw_info_format (NDI_UNIQUE, 0, pl, "%s will cost you %s.", query_name (tmp), query_cost_string (tmp, pl, F_BUY | F_SHOP)); |
312 | new_draw_info_format (NDI_UNIQUE, 0, pl, "%s will cost you %s.", query_name (tmp), query_cost_string (tmp, pl, F_BUY | F_SHOP)); |
324 | else |
313 | else |
325 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You pick up the %s.", query_name (tmp)); |
314 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You pick up the %s.", query_name (tmp)); |
… | |
… | |
539 | new_draw_info (NDI_UNIQUE, 0, op, "There is nothing to pick up."); |
528 | new_draw_info (NDI_UNIQUE, 0, op, "There is nothing to pick up."); |
540 | } |
529 | } |
541 | |
530 | |
542 | return 0; |
531 | return 0; |
543 | } |
532 | } |
544 | |
|
|
545 | |
533 | |
546 | /* |
534 | /* |
547 | * This function was part of drop, now is own function. |
535 | * This function was part of drop, now is own function. |
548 | * Player 'op' tries to put object 'tmp' into sack 'sack', |
536 | * Player 'op' tries to put object 'tmp' into sack 'sack', |
549 | * if nrof is non zero, then nrof objects is tried to put into sack. |
537 | * if nrof is non zero, then nrof objects is tried to put into sack. |
… | |
… | |
565 | return; |
553 | return; |
566 | } |
554 | } |
567 | |
555 | |
568 | if (tmp->type == CONTAINER && tmp->inv) |
556 | if (tmp->type == CONTAINER && tmp->inv) |
569 | { |
557 | { |
570 | |
|
|
571 | /* Eneq(@csd.uu.se): If the object to be dropped is a container |
558 | /* Eneq(@csd.uu.se): If the object to be dropped is a container |
572 | * we instead move the contents of that container into the active |
559 | * we instead move the contents of that container into the active |
573 | * container, this is only done if the object has something in it. |
560 | * container, this is only done if the object has something in it. |
574 | */ |
561 | */ |
575 | sack2 = tmp; |
562 | sack2 = tmp; |
… | |
… | |
606 | return; |
593 | return; |
607 | |
594 | |
608 | /* we want to put some portion of the item into the container */ |
595 | /* we want to put some portion of the item into the container */ |
609 | if (nrof && tmp->nrof != nrof) |
596 | if (nrof && tmp->nrof != nrof) |
610 | { |
597 | { |
611 | object *tmp2 = tmp; |
598 | if (!can_split (op, tmp, nrof)) |
612 | |
|
|
613 | tmp = get_split_ob (tmp, nrof); |
|
|
614 | |
|
|
615 | if (!tmp) |
|
|
616 | { |
|
|
617 | new_draw_info (NDI_UNIQUE, 0, op, errmsg); |
|
|
618 | return; |
599 | return; |
619 | } |
|
|
620 | /* Tell a client what happened other objects */ |
|
|
621 | if (tmp2->destroyed ()) |
|
|
622 | esrv_del_item (op->contr, tmp2->count); |
|
|
623 | else /* this can proably be replaced with an update */ |
|
|
624 | esrv_send_item (op, tmp2); |
|
|
625 | } |
600 | } |
626 | else |
601 | else |
627 | tmp->remove (); |
602 | tmp->remove (); |
628 | |
603 | |
629 | new_draw_info_format (NDI_UNIQUE, 0, op, "You put the %s in %s.", query_name (tmp), query_name (sack)); |
604 | new_draw_info_format (NDI_UNIQUE, 0, op, "You put the %s in %s.", query_name (tmp), query_name (sack)); |
… | |
… | |
668 | /* We are only dropping some of the items. We split the current object |
643 | /* We are only dropping some of the items. We split the current object |
669 | * off |
644 | * off |
670 | */ |
645 | */ |
671 | if (nrof && tmp->nrof != nrof) |
646 | if (nrof && tmp->nrof != nrof) |
672 | { |
647 | { |
673 | object *tmp2 = tmp; |
648 | if (!can_split (op, tmp, nrof)) |
674 | |
|
|
675 | tmp = get_split_ob (tmp, nrof); |
|
|
676 | if (!tmp) |
|
|
677 | { |
|
|
678 | new_draw_info (NDI_UNIQUE, 0, op, errmsg); |
|
|
679 | return; |
649 | return; |
680 | } |
|
|
681 | /* Tell a client what happened rest of objects. tmp2 is now the |
|
|
682 | * original object |
|
|
683 | */ |
|
|
684 | if (op->type == PLAYER) |
|
|
685 | { |
|
|
686 | if (tmp2->destroyed ()) |
|
|
687 | esrv_del_item (op->contr, tmp2->count); |
|
|
688 | else |
|
|
689 | esrv_send_item (op, tmp2); |
|
|
690 | } |
|
|
691 | } |
650 | } |
692 | else |
651 | else |
693 | tmp->remove (); |
652 | tmp->remove (); |
694 | |
653 | |
695 | if (INVOKE_OBJECT (DROP, tmp, ARG_OBJECT (op))) |
654 | if (INVOKE_OBJECT (DROP, tmp, ARG_OBJECT (op))) |