… | |
… | |
264 | |
264 | |
265 | flags = query_flags (head); |
265 | flags = query_flags (head); |
266 | if (QUERY_FLAG (head, FLAG_NO_PICK)) |
266 | if (QUERY_FLAG (head, FLAG_NO_PICK)) |
267 | flags |= F_NOPICK; |
267 | flags |= F_NOPICK; |
268 | |
268 | |
269 | if (!(ns.faces_sent[head->face->number] & NS_FACESENT_FACE)) |
269 | ns.send_face (head->face); |
270 | esrv_send_face (&ns, head->face->number, 0); |
270 | ns.flush_fx (); |
271 | |
271 | |
272 | if (QUERY_FLAG (head, FLAG_ANIMATE) && !ns.anims_sent[head->animation_id]) |
272 | if (QUERY_FLAG (head, FLAG_ANIMATE) && !ns.anims_sent[head->animation_id]) |
273 | esrv_send_animation (&ns, head->animation_id); |
273 | ns.send_animation (head->animation_id); |
274 | |
274 | |
275 | sl << uint32 (head->count) |
275 | sl << uint32 (head->count) |
276 | << uint32 (flags) |
276 | << uint32 (flags) |
277 | << uint32 (QUERY_FLAG (head, FLAG_NO_PICK) ? -1 : WEIGHT (head)) |
277 | << uint32 (QUERY_FLAG (head, FLAG_NO_PICK) ? -1 : WEIGHT (head)) |
278 | << uint32 (head->face->number); |
278 | << uint32 (head->face); |
279 | |
279 | |
280 | if (!head->custom_name) |
280 | if (!head->custom_name) |
281 | { |
281 | { |
282 | strncpy (item_n, query_base_name (head, 0), 127); |
282 | strncpy (item_n, query_base_name (head, 0), 127); |
283 | item_n[127] = 0; |
283 | item_n[127] = 0; |
… | |
… | |
304 | { |
304 | { |
305 | if (head->anim_speed) |
305 | if (head->anim_speed) |
306 | anim_speed = head->anim_speed; |
306 | anim_speed = head->anim_speed; |
307 | else |
307 | else |
308 | { |
308 | { |
309 | if (FABS (head->speed) < 0.001) |
309 | if (fabs (head->speed) < 0.001) |
310 | anim_speed = 255; |
310 | anim_speed = 255; |
311 | else if (FABS (head->speed) >= 1.0) |
311 | else if (fabs (head->speed) >= 1.0) |
312 | anim_speed = 1; |
312 | anim_speed = 1; |
313 | else |
313 | else |
314 | anim_speed = (int) (1.0 / FABS (head->speed)); |
314 | anim_speed = (int) (1.0 / fabs (head->speed)); |
315 | } |
315 | } |
316 | |
316 | |
317 | if (anim_speed > 255) |
317 | if (anim_speed > 255) |
318 | anim_speed = 255; |
318 | anim_speed = 255; |
319 | } |
319 | } |
… | |
… | |
334 | */ |
334 | */ |
335 | void |
335 | void |
336 | esrv_draw_look (object *pl) |
336 | esrv_draw_look (object *pl) |
337 | { |
337 | { |
338 | int got_one = 0, start_look = 0, end_look = 0; |
338 | int got_one = 0, start_look = 0, end_look = 0; |
339 | char buf[MAX_BUF]; |
|
|
340 | |
339 | |
341 | if (!pl->contr->ns->update_look) |
340 | if (!pl->contr->ns->update_look) |
342 | { |
341 | { |
343 | LOG (llevDebug, "esrv_draw_look called when update_look was not set\n"); |
342 | LOG (llevDebug, "esrv_draw_look called when update_look was not set (player %s)\n", &pl->name); |
344 | return; |
343 | return; |
345 | } |
344 | } |
346 | else |
345 | else |
347 | pl->contr->ns->update_look = 0; |
346 | pl->contr->ns->update_look = 0; |
348 | |
347 | |
… | |
… | |
357 | packet sl; |
356 | packet sl; |
358 | sl.printf ("item%d ", pl->contr->ns->itemcmd); |
357 | sl.printf ("item%d ", pl->contr->ns->itemcmd); |
359 | |
358 | |
360 | sl << uint32 (0); |
359 | sl << uint32 (0); |
361 | |
360 | |
362 | if (!(pl->contr->ns->faces_sent[empty_face->number] & NS_FACESENT_FACE)) |
361 | pl->contr->ns->send_face (empty_face); |
363 | esrv_send_face (pl->contr->ns, empty_face->number, 0); |
362 | pl->contr->ns->flush_fx (); |
364 | |
363 | |
365 | if (pl->contr->ns->look_position) |
364 | if (pl->contr->ns->look_position) |
366 | { |
365 | { |
367 | char buf[80]; |
366 | char buf[80]; |
368 | snprintf (buf, 80, "Apply this to see %d previous items", FLOORBOX_PAGESIZE); |
367 | snprintf (buf, 80, "Apply this to see %d previous items", FLOORBOX_PAGESIZE); |
369 | |
368 | |
370 | sl << uint32 (0x80000000 | (pl->contr->ns->look_position - FLOORBOX_PAGESIZE)) |
369 | sl << uint32 (0x80000000 | (pl->contr->ns->look_position - FLOORBOX_PAGESIZE)) |
371 | << uint32 (0) |
370 | << uint32 (0) |
372 | << sint32 (-1) |
371 | << sint32 (-1) |
373 | << uint32 (empty_face->number) |
372 | << uint32 (empty_face) |
374 | << data8 (buf) |
373 | << data8 (buf) |
375 | << uint16 (0) |
374 | << uint16 (0) |
376 | << uint8 (0) |
375 | << uint8 (0) |
377 | << uint32 (0); |
376 | << uint32 (0); |
378 | |
377 | |
… | |
… | |
405 | * we notice the special tag the object has, and act accordingly. |
404 | * we notice the special tag the object has, and act accordingly. |
406 | */ |
405 | */ |
407 | sl << uint32 (0x80000000 | (pl->contr->ns->look_position + FLOORBOX_PAGESIZE)) |
406 | sl << uint32 (0x80000000 | (pl->contr->ns->look_position + FLOORBOX_PAGESIZE)) |
408 | << uint32 (0) |
407 | << uint32 (0) |
409 | << uint32 ((uint32) - 1) |
408 | << uint32 ((uint32) - 1) |
410 | << uint32 (empty_face->number) |
409 | << uint32 (empty_face) |
411 | << data8 ("Apply this to see next group of items") |
410 | << data8 ("Apply this to see next group of items") |
412 | << uint16 (0) |
411 | << uint16 (0) |
413 | << uint8 (0) |
412 | << uint8 (0) |
414 | << uint32 (0); |
413 | << uint32 (0); |
415 | |
414 | |
… | |
… | |
448 | * Sends whole inventory. |
447 | * Sends whole inventory. |
449 | */ |
448 | */ |
450 | void |
449 | void |
451 | esrv_send_inventory (object *pl, object *op) |
450 | esrv_send_inventory (object *pl, object *op) |
452 | { |
451 | { |
|
|
452 | if (!pl->contr->ns)//D |
|
|
453 | return; |
|
|
454 | |
453 | int got_one = 0; |
455 | int got_one = 0; |
454 | |
456 | |
455 | pl->contr->ns->send_packet_printf ("delinv %d", op->count); |
457 | pl->contr->ns->send_packet_printf ("delinv %d", op->count); |
456 | |
458 | |
457 | packet sl; |
459 | packet sl; |
… | |
… | |
499 | * |
501 | * |
500 | * flags is a list of values to update |
502 | * flags is a list of values to update |
501 | * to the client (as defined in newclient.h - might as well use the |
503 | * to the client (as defined in newclient.h - might as well use the |
502 | * same value both places. |
504 | * same value both places. |
503 | */ |
505 | */ |
504 | |
|
|
505 | void |
506 | void |
506 | esrv_update_item (int flags, object *pl, object *op) |
507 | esrv_update_item (int flags, object *pl, object *op) |
507 | { |
508 | { |
508 | /* If we have a request to send the player item, skip a few checks. */ |
509 | /* If we have a request to send the player item, skip a few checks. */ |
509 | if (op != pl) |
510 | if (op != pl) |
… | |
… | |
554 | ns->last_weight = weight; |
555 | ns->last_weight = weight; |
555 | } |
556 | } |
556 | |
557 | |
557 | if (flags & UPD_FACE) |
558 | if (flags & UPD_FACE) |
558 | { |
559 | { |
559 | if (!(ns->faces_sent[op->face->number] & NS_FACESENT_FACE)) |
560 | ns->send_face (op->face); |
560 | esrv_send_face (ns, op->face->number, 0); |
561 | ns->flush_fx (); |
561 | |
|
|
562 | sl << uint32 (op->face->number); |
562 | sl << uint32 (op->face); |
563 | } |
563 | } |
564 | |
564 | |
565 | if (flags & UPD_NAME) |
565 | if (flags & UPD_NAME) |
566 | { |
566 | { |
567 | int len; |
567 | int len; |
… | |
… | |
601 | { |
601 | { |
602 | if (op->anim_speed) |
602 | if (op->anim_speed) |
603 | anim_speed = op->anim_speed; |
603 | anim_speed = op->anim_speed; |
604 | else |
604 | else |
605 | { |
605 | { |
606 | if (FABS (op->speed) < 0.001) |
606 | if (fabs (op->speed) < 0.001) |
607 | anim_speed = 255; |
607 | anim_speed = 255; |
608 | else if (FABS (op->speed) >= 1.0) |
608 | else if (fabs (op->speed) >= 1.0) |
609 | anim_speed = 1; |
609 | anim_speed = 1; |
610 | else |
610 | else |
611 | anim_speed = (int) (1.0 / FABS (op->speed)); |
611 | anim_speed = (int) (1.0 / fabs (op->speed)); |
612 | } |
612 | } |
613 | |
613 | |
614 | if (anim_speed > 255) |
614 | if (anim_speed > 255) |
615 | anim_speed = 255; |
615 | anim_speed = 255; |
616 | } |
616 | } |
… | |
… | |
628 | * Sends item's info to player. |
628 | * Sends item's info to player. |
629 | */ |
629 | */ |
630 | void |
630 | void |
631 | esrv_send_item (object *pl, object *op) |
631 | esrv_send_item (object *pl, object *op) |
632 | { |
632 | { |
|
|
633 | if (!pl->contr->ns) |
|
|
634 | return; |
|
|
635 | |
633 | /* If this is not the player object, do some more checks */ |
636 | /* If this is not the player object, do some more checks */ |
634 | if (op != pl) |
637 | if (op != pl) |
635 | { |
638 | { |
636 | /* We only send 'visibile' objects to the client */ |
639 | /* We only send 'visibile' objects to the client */ |
637 | if (!op->client_visible ()) |
640 | if (!op->client_visible ()) |
… | |
… | |
664 | |
667 | |
665 | /** |
668 | /** |
666 | * Tells the client to delete an item. Uses the item |
669 | * Tells the client to delete an item. Uses the item |
667 | * command with a -1 location. |
670 | * command with a -1 location. |
668 | */ |
671 | */ |
669 | |
|
|
670 | void |
672 | void |
671 | esrv_del_item (player *pl, int tag) |
673 | esrv_del_item (player *pl, int tag) |
672 | { |
674 | { |
|
|
675 | if (!pl->ns) |
|
|
676 | return; |
|
|
677 | |
673 | packet sl ("delitem"); |
678 | packet sl ("delitem"); |
674 | |
679 | |
675 | sl << uint32 (tag); |
680 | sl << uint32 (tag); |
676 | |
681 | |
677 | pl->ns->send_packet (sl); |
682 | pl->ns->send_packet (sl); |
… | |
… | |
686 | |
691 | |
687 | /** |
692 | /** |
688 | * Takes a player and object count (tag) and returns the actual object |
693 | * Takes a player and object count (tag) and returns the actual object |
689 | * pointer, or null if it can't be found. |
694 | * pointer, or null if it can't be found. |
690 | */ |
695 | */ |
691 | |
|
|
692 | object * |
696 | object * |
693 | esrv_get_ob_from_count (object *pl, tag_t count) |
697 | esrv_get_ob_from_count (object *pl, tag_t count) |
694 | { |
698 | { |
695 | object *op, *tmp; |
|
|
696 | |
|
|
697 | if (pl->count == count) |
699 | if (pl->count == count) |
698 | return pl; |
700 | return pl; |
699 | |
701 | |
700 | for (op = pl->inv; op; op = op->below) |
702 | for (object *op = pl->inv; op; op = op->below) |
701 | if (op->count == count) |
703 | if (op->count == count) |
702 | return op; |
704 | return op; |
703 | else if (op->type == CONTAINER && pl->container == op) |
705 | else if (op->type == CONTAINER && pl->container == op) |
704 | for (tmp = op->inv; tmp; tmp = tmp->below) |
706 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
705 | if (tmp->count == count) |
707 | if (tmp->count == count) |
706 | return tmp; |
708 | return tmp; |
707 | |
709 | |
708 | for (op = GET_MAP_OB (pl->map, pl->x, pl->y); op; op = op->above) |
710 | for (object *op = GET_MAP_OB (pl->map, pl->x, pl->y); op; op = op->above) |
709 | if (op->head && op->head->count == count) |
711 | if (op->head && op->head->count == count) |
710 | return op; |
712 | return op; |
711 | else if (op->count == count) |
713 | else if (op->count == count) |
712 | return op; |
714 | return op; |
713 | else if (op->type == CONTAINER && pl->container == op) |
715 | else if (op->type == CONTAINER && pl->container == op) |
714 | for (tmp = op->inv; tmp; tmp = tmp->below) |
716 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
715 | if (tmp->count == count) |
717 | if (tmp->count == count) |
716 | return tmp; |
718 | return tmp; |
717 | |
719 | |
|
|
720 | #if 0 |
|
|
721 | /* If the high bit is set, player examined a pseudo object. */ |
|
|
722 | if (count & 0x80000000) |
|
|
723 | return 0; |
|
|
724 | #endif |
|
|
725 | |
718 | return 0; |
726 | return 0; |
719 | } |
727 | } |
720 | |
728 | |
721 | |
|
|
722 | /** Client wants to examine some object. So lets do so. */ |
729 | /** Client wants to examine some object. So lets do so. */ |
723 | void |
730 | void |
724 | ExamineCmd (char *buf, int len, player *pl) |
731 | ExamineCmd (char *buf, int len, player *pl) |
725 | { |
732 | { |
726 | tag_t tag = atoi (buf); |
733 | tag_t tag = atoi (buf); |
727 | |
|
|
728 | /* If the high bit is set, player examined a pseudo object. */ |
|
|
729 | if (tag & 0x80000000) |
|
|
730 | return; |
|
|
731 | |
734 | |
732 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
735 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
733 | |
736 | |
734 | if (!op) |
737 | if (!op) |
735 | { |
738 | { |
736 | LOG (llevDebug, "Player '%s' tried to examine the unknown object (%ld)\n", &pl->ob->name, tag); |
739 | LOG (llevDebug, "Player '%s' tried to examine the unknown object (%ld)\n", &pl->ob->name, tag); |
737 | return; |
740 | return; |
738 | } |
741 | } |
739 | |
742 | |
740 | examine (pl->ob, op); |
743 | examine (pl->ob, op); |
|
|
744 | } |
|
|
745 | |
|
|
746 | /** Client wants to examine some object. So lets do so. */ |
|
|
747 | void |
|
|
748 | ExCmd (char *buf, int len, player *pl) |
|
|
749 | { |
|
|
750 | tag_t tag = atoi (buf); |
|
|
751 | |
|
|
752 | if (object *op = esrv_get_ob_from_count (pl->ob, tag)) |
|
|
753 | { |
|
|
754 | std::string s = op->describe (pl->ob); |
|
|
755 | |
|
|
756 | packet sl ("ex"); |
|
|
757 | sl << ber32 (tag) << s.c_str (); |
|
|
758 | |
|
|
759 | pl->ns->send_packet (sl); |
|
|
760 | } |
741 | } |
761 | } |
742 | |
762 | |
743 | /** Client wants to apply some object. Lets do so. */ |
763 | /** Client wants to apply some object. Lets do so. */ |
744 | void |
764 | void |
745 | ApplyCmd (char *buf, int len, player *pl) |
765 | ApplyCmd (char *buf, int len, player *pl) |
… | |
… | |
832 | |
852 | |
833 | m = get_map_from_coord (op->map, &x, &y); |
853 | m = get_map_from_coord (op->map, &x, &y); |
834 | if (!m) |
854 | if (!m) |
835 | return; |
855 | return; |
836 | |
856 | |
837 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL && tmp->above != NULL; tmp = tmp->above); |
857 | for (tmp = GET_MAP_OB (m, x, y); tmp && tmp->above; tmp = tmp->above) |
|
|
858 | ; |
838 | |
859 | |
839 | for (; tmp != NULL; tmp = tmp->below) |
860 | for (; tmp; tmp = tmp->below) |
840 | { |
861 | { |
841 | if (tmp->invisible && !QUERY_FLAG (op, FLAG_WIZ)) |
862 | if (tmp->invisible && !QUERY_FLAG (op, FLAG_WIZ)) |
842 | continue; |
863 | continue; |
843 | |
864 | |
844 | if (!flag) |
865 | if (!flag) |
… | |
… | |
873 | else |
894 | else |
874 | new_draw_info (NDI_UNIQUE, 0, op, "You see nothing."); |
895 | new_draw_info (NDI_UNIQUE, 0, op, "You see nothing."); |
875 | } |
896 | } |
876 | } |
897 | } |
877 | |
898 | |
878 | |
|
|
879 | |
|
|
880 | /** Client wants to look at some object. Lets do so. */ |
899 | /** Client wants to look at some object. Lets do so. */ |
881 | void |
900 | void |
882 | LookAt (char *buf, int len, player *pl) |
901 | LookAt (char *buf, int len, player *pl) |
883 | { |
902 | { |
884 | int dx, dy; |
903 | int dx, dy; |
885 | char *cp; |
904 | char *cp; |
886 | |
905 | |
887 | dx = atoi (buf); |
906 | dx = atoi (buf); |
888 | if (!(cp = strchr (buf, ' '))) |
907 | if (!(cp = strchr (buf, ' '))) |
889 | { |
|
|
890 | return; |
908 | return; |
891 | } |
909 | |
892 | dy = atoi (cp); |
910 | dy = atoi (cp); |
893 | |
|
|
894 | if (FABS (dx) > pl->ns->mapx / 2 || FABS (dy) > pl->ns->mapy / 2) |
911 | if (fabs (dx) > pl->ns->mapx / 2 || fabs (dy) > pl->ns->mapy / 2) |
895 | return; |
912 | return; |
896 | |
913 | |
897 | if (pl->blocked_los[dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2]) |
914 | if (pl->blocked_los[dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2]) |
898 | return; |
915 | return; |
899 | |
916 | |