… | |
… | |
30 | * This containes item logic for client/server. It doesn't contain |
30 | * This containes item logic for client/server. It doesn't contain |
31 | * the actual commands that send the data, but does contain |
31 | * the actual commands that send the data, but does contain |
32 | * the logic for what items should be sent. |
32 | * the logic for what items should be sent. |
33 | */ |
33 | */ |
34 | |
34 | |
35 | |
|
|
36 | #include <global.h> |
35 | #include <global.h> |
37 | #include <object.h> /* LOOK_OBJ */ |
36 | #include <object.h> /* LOOK_OBJ */ |
38 | #include <sproto.h> |
37 | #include <sproto.h> |
39 | |
38 | |
40 | /** This is the maximum number of bytes we expect any one item to take up */ |
39 | /** This is the maximum number of bytes we expect any one item to take up */ |
… | |
… | |
46 | * |
45 | * |
47 | ******************************************************************************/ |
46 | ******************************************************************************/ |
48 | |
47 | |
49 | /** |
48 | /** |
50 | * This is a similar to query_name, but returns flags |
49 | * This is a similar to query_name, but returns flags |
51 | * to be sended to client. |
50 | * to be sent to client. |
52 | */ |
51 | */ |
53 | unsigned int |
52 | unsigned int |
54 | query_flags (object *op) |
53 | query_flags (object *op) |
55 | { |
54 | { |
56 | unsigned int flags = 0; |
55 | unsigned int flags = 0; |
57 | |
56 | |
58 | if (QUERY_FLAG (op, FLAG_APPLIED)) |
57 | if (QUERY_FLAG (op, FLAG_APPLIED)) |
59 | { |
58 | { |
60 | switch (op->type) |
59 | switch (op->type) |
61 | { |
60 | { |
62 | case BOW: |
61 | case BOW: |
63 | case WAND: |
62 | case WAND: |
64 | case ROD: |
63 | case ROD: |
65 | case HORN: |
64 | case HORN: |
66 | flags = a_readied; |
65 | flags = a_readied; |
67 | break; |
66 | break; |
68 | case WEAPON: |
67 | case WEAPON: |
69 | flags = a_wielded; |
68 | flags = a_wielded; |
70 | break; |
69 | break; |
71 | case SKILL: |
70 | case SKILL: |
72 | case ARMOUR: |
71 | case ARMOUR: |
73 | case HELMET: |
72 | case HELMET: |
74 | case SHIELD: |
73 | case SHIELD: |
75 | case RING: |
74 | case RING: |
76 | case BOOTS: |
75 | case BOOTS: |
77 | case GLOVES: |
76 | case GLOVES: |
78 | case AMULET: |
77 | case AMULET: |
79 | case GIRDLE: |
78 | case GIRDLE: |
80 | case BRACERS: |
79 | case BRACERS: |
81 | case CLOAK: |
80 | case CLOAK: |
82 | flags = a_worn; |
81 | flags = a_worn; |
83 | break; |
82 | break; |
84 | case CONTAINER: |
83 | case CONTAINER: |
85 | flags = a_active; |
84 | flags = a_active; |
86 | break; |
85 | break; |
87 | default: |
86 | default: |
88 | flags = a_applied; |
87 | flags = a_applied; |
89 | break; |
88 | break; |
90 | } |
89 | } |
91 | } |
90 | } |
|
|
91 | |
92 | if (op->type == CONTAINER && ((op->env && op->env->container == op) || (!op->env && QUERY_FLAG (op, FLAG_APPLIED)))) |
92 | if (op->type == CONTAINER && ((op->env && op->env->container == op) || (!op->env && QUERY_FLAG (op, FLAG_APPLIED)))) |
93 | flags |= F_OPEN; |
93 | flags |= F_OPEN; |
94 | |
94 | |
95 | if (QUERY_FLAG (op, FLAG_KNOWN_CURSED)) |
95 | if (QUERY_FLAG (op, FLAG_KNOWN_CURSED)) |
96 | { |
96 | { |
97 | if (QUERY_FLAG (op, FLAG_DAMNED)) |
97 | if (QUERY_FLAG (op, FLAG_DAMNED)) |
98 | flags |= F_DAMNED; |
98 | flags |= F_DAMNED; |
99 | else if (QUERY_FLAG (op, FLAG_CURSED)) |
99 | else if (QUERY_FLAG (op, FLAG_CURSED)) |
100 | flags |= F_CURSED; |
100 | flags |= F_CURSED; |
101 | } |
101 | } |
|
|
102 | |
102 | if (QUERY_FLAG (op, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (op, FLAG_IDENTIFIED)) |
103 | if (QUERY_FLAG (op, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (op, FLAG_IDENTIFIED)) |
103 | flags |= F_MAGIC; |
104 | flags |= F_MAGIC; |
104 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
105 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
105 | flags |= F_UNPAID; |
106 | flags |= F_UNPAID; |
106 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
107 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
… | |
… | |
185 | SET_FLAG (head, FLAG_CLIENT_SENT); |
186 | SET_FLAG (head, FLAG_CLIENT_SENT); |
186 | } |
187 | } |
187 | |
188 | |
188 | |
189 | |
189 | /** |
190 | /** |
190 | * Send the look window. Don't need to do animations here |
191 | * Send the look window. Don't need to do animations here |
191 | * This sends all the faces to the client, not just updates. This is |
192 | * This sends all the faces to the client, not just updates. This is |
192 | * because object ordering would otherwise be inconsistent |
193 | * because object ordering would otherwise be inconsistent. |
193 | */ |
194 | */ |
194 | |
|
|
195 | void |
195 | void |
196 | esrv_draw_look (object *pl) |
196 | esrv_draw_look (object *pl) |
197 | { |
197 | { |
198 | object *tmp, *last; |
198 | object *tmp, *last; |
199 | int got_one = 0, start_look = 0, end_look = 0; |
199 | int got_one = 0, start_look = 0, end_look = 0; |
… | |
… | |
298 | sl.reset (); |
298 | sl.reset (); |
299 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
299 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
300 | sl << uint32 (0); |
300 | sl << uint32 (0); |
301 | got_one = 0; |
301 | got_one = 0; |
302 | } |
302 | } |
303 | } /* If LOOK_OBJ() */ |
303 | } |
304 | } |
304 | } |
305 | |
305 | |
306 | if (got_one) |
306 | if (got_one) |
307 | pl->contr->socket->send_packet (sl); |
307 | pl->contr->socket->send_packet (sl); |
308 | |
308 | |
… | |
… | |
358 | } /* If LOOK_OBJ() */ |
358 | } /* If LOOK_OBJ() */ |
359 | } |
359 | } |
360 | |
360 | |
361 | if (got_one) |
361 | if (got_one) |
362 | pl->contr->socket->send_packet (sl); |
362 | pl->contr->socket->send_packet (sl); |
363 | |
|
|
364 | } |
363 | } |
365 | |
364 | |
366 | /** |
365 | /** |
367 | * Updates object *op for player *pl. |
366 | * Updates object *op for player *pl. |
368 | * |
367 | * |
… | |
… | |
523 | |
522 | |
524 | add_object_to_socklist (*pl->contr->socket, sl, op); |
523 | add_object_to_socklist (*pl->contr->socket, sl, op); |
525 | |
524 | |
526 | pl->contr->socket->send_packet (sl); |
525 | pl->contr->socket->send_packet (sl); |
527 | SET_FLAG (op, FLAG_CLIENT_SENT); |
526 | SET_FLAG (op, FLAG_CLIENT_SENT); |
528 | |
|
|
529 | } |
527 | } |
530 | |
528 | |
531 | /** |
529 | /** |
532 | * Tells the client to delete an item. Uses the item |
530 | * Tells the client to delete an item. Uses the item |
533 | * command with a -1 location. |
531 | * command with a -1 location. |
… | |
… | |
571 | for (tmp = op->inv; tmp; tmp = tmp->below) |
569 | for (tmp = op->inv; tmp; tmp = tmp->below) |
572 | if (tmp->count == count) |
570 | if (tmp->count == count) |
573 | return tmp; |
571 | return tmp; |
574 | |
572 | |
575 | for (op = get_map_ob (pl->map, pl->x, pl->y); op; op = op->above) |
573 | for (op = get_map_ob (pl->map, pl->x, pl->y); op; op = op->above) |
576 | if (op->head != NULL && op->head->count == count) |
574 | if (op->head && op->head->count == count) |
577 | return op; |
575 | return op; |
578 | else if (op->count == count) |
576 | else if (op->count == count) |
579 | return op; |
577 | return op; |
580 | else if (op->type == CONTAINER && pl->container == op) |
578 | else if (op->type == CONTAINER && pl->container == op) |
581 | for (tmp = op->inv; tmp; tmp = tmp->below) |
579 | for (tmp = op->inv; tmp; tmp = tmp->below) |
582 | if (tmp->count == count) |
580 | if (tmp->count == count) |
583 | return tmp; |
581 | return tmp; |
584 | |
582 | |
585 | return NULL; |
583 | return 0; |
586 | } |
584 | } |
587 | |
585 | |
588 | |
586 | |
589 | /** Client wants to examine some object. So lets do so. */ |
587 | /** Client wants to examine some object. So lets do so. */ |
590 | void |
588 | void |
… | |
… | |
605 | } |
603 | } |
606 | |
604 | |
607 | examine (pl->ob, op); |
605 | examine (pl->ob, op); |
608 | } |
606 | } |
609 | |
607 | |
610 | /** Client wants to apply some object. Lets do so. */ |
608 | /** Client wants to apply some object. Lets do so. */ |
611 | void |
609 | void |
612 | ApplyCmd (char *buf, int len, player *pl) |
610 | ApplyCmd (char *buf, int len, player *pl) |
613 | { |
611 | { |
614 | tag_t tag = atoi (buf); |
612 | tag_t tag = atoi (buf); |
615 | |
613 | |
… | |
… | |
799 | } |
797 | } |
800 | |
798 | |
801 | esrv_update_item (UPD_WEIGHT, pl, op); |
799 | esrv_update_item (UPD_WEIGHT, pl, op); |
802 | } |
800 | } |
803 | else |
801 | else |
804 | { |
|
|
805 | drop_object (pl, op, nrof); |
802 | drop_object (pl, op, nrof); |
806 | } |
803 | |
807 | return; |
804 | return; |
808 | } |
805 | } |
809 | else if (to == pl->count) |
806 | else if (to == pl->count) |
810 | { /* pick it up to the inventory */ |
807 | { /* pick it up to the inventory */ |
811 | /* return if player has already picked it up */ |
808 | /* return if player has already picked it up */ |
… | |
… | |
828 | * has already been done (eg, it can be picked up and fits in |
825 | * has already been done (eg, it can be picked up and fits in |
829 | * in a sack, so check for those things. We should also check |
826 | * in a sack, so check for those things. We should also check |
830 | * an make sure env is in fact a container for that matter. |
827 | * an make sure env is in fact a container for that matter. |
831 | */ |
828 | */ |
832 | if (env->type == CONTAINER && can_pick (pl, op) && sack_can_hold (pl, env, op, nrof)) |
829 | if (env->type == CONTAINER && can_pick (pl, op) && sack_can_hold (pl, env, op, nrof)) |
833 | { |
|
|
834 | put_object_in_sack (pl, env, op, nrof); |
830 | put_object_in_sack (pl, env, op, nrof); |
835 | } |
|
|
836 | } |
831 | } |
837 | |
832 | |