1 | |
1 | |
2 | /* |
2 | /* |
3 | * static char *rcsid_item_c = |
3 | * static char *rcsid_item_c = |
4 | * "$Id: item.C,v 1.4 2006/09/03 00:18:43 root Exp $"; |
4 | * "$Id: item.C,v 1.5 2006/09/10 13:43:33 root Exp $"; |
5 | */ |
5 | */ |
6 | |
6 | |
7 | /* |
7 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
8 | CrossFire, A Multiplayer game for X-windows |
9 | |
9 | |
… | |
… | |
38 | * the logic for what items should be sent. |
38 | * the logic for what items should be sent. |
39 | */ |
39 | */ |
40 | |
40 | |
41 | |
41 | |
42 | #include <global.h> |
42 | #include <global.h> |
43 | #include <object.h> /* LOOK_OBJ */ |
43 | #include <object.h> /* LOOK_OBJ */ |
44 | #include <newclient.h> |
44 | #include <newclient.h> |
45 | #include <newserver.h> |
45 | #include <newserver.h> |
46 | #include <sproto.h> |
46 | #include <sproto.h> |
47 | |
47 | |
48 | /** This is the maximum number of bytes we expect any one item to take up */ |
48 | /** This is the maximum number of bytes we expect any one item to take up */ |
… | |
… | |
60 | * This is a simple function that we use a lot here. It basically |
60 | * This is a simple function that we use a lot here. It basically |
61 | * adds the specified buffer into the socklist, but prepends a |
61 | * adds the specified buffer into the socklist, but prepends a |
62 | * single byte in length. If the data is longer than that byte, it is |
62 | * single byte in length. If the data is longer than that byte, it is |
63 | * truncated approprately. |
63 | * truncated approprately. |
64 | */ |
64 | */ |
|
|
65 | inline void |
65 | inline void add_stringlen_to_sockbuf(const char *buf, SockList *sl) |
66 | add_stringlen_to_sockbuf (const char *buf, SockList * sl) |
66 | { |
67 | { |
67 | int len; |
68 | int len; |
68 | |
69 | |
69 | len=strlen(buf); |
70 | len = strlen (buf); |
70 | if (len>255) len=255; |
71 | if (len > 255) |
|
|
72 | len = 255; |
71 | SockList_AddChar(sl, (char) len); |
73 | SockList_AddChar (sl, (char) len); |
72 | strncpy((char*)sl->buf+sl->len, buf,len); |
74 | strncpy ((char *) sl->buf + sl->len, buf, len); |
73 | sl->len += len; |
75 | sl->len += len; |
74 | } |
76 | } |
75 | |
77 | |
76 | /** |
78 | /** |
77 | * This is a similar to query_name, but returns flags |
79 | * This is a similar to query_name, but returns flags |
78 | * to be sended to client. |
80 | * to be sended to client. |
79 | */ |
81 | */ |
|
|
82 | unsigned int |
80 | unsigned int query_flags (object *op) |
83 | query_flags (object *op) |
81 | { |
84 | { |
82 | unsigned int flags = 0; |
85 | unsigned int flags = 0; |
83 | |
86 | |
84 | if(QUERY_FLAG(op,FLAG_APPLIED)) { |
87 | if (QUERY_FLAG (op, FLAG_APPLIED)) |
|
|
88 | { |
85 | switch(op->type) { |
89 | switch (op->type) |
|
|
90 | { |
86 | case BOW: |
91 | case BOW: |
87 | case WAND: |
92 | case WAND: |
88 | case ROD: |
93 | case ROD: |
89 | case HORN: |
94 | case HORN: |
90 | flags = a_readied; |
95 | flags = a_readied; |
91 | break; |
96 | break; |
92 | case WEAPON: |
97 | case WEAPON: |
93 | flags = a_wielded; |
98 | flags = a_wielded; |
94 | break; |
99 | break; |
95 | case SKILL: |
100 | case SKILL: |
96 | case ARMOUR: |
101 | case ARMOUR: |
97 | case HELMET: |
102 | case HELMET: |
98 | case SHIELD: |
103 | case SHIELD: |
99 | case RING: |
104 | case RING: |
100 | case BOOTS: |
105 | case BOOTS: |
101 | case GLOVES: |
106 | case GLOVES: |
102 | case AMULET: |
107 | case AMULET: |
103 | case GIRDLE: |
108 | case GIRDLE: |
104 | case BRACERS: |
109 | case BRACERS: |
105 | case CLOAK: |
110 | case CLOAK: |
106 | flags = a_worn; |
111 | flags = a_worn; |
107 | break; |
112 | break; |
108 | case CONTAINER: |
113 | case CONTAINER: |
109 | flags = a_active; |
114 | flags = a_active; |
110 | break; |
115 | break; |
111 | default: |
116 | default: |
112 | flags = a_applied; |
117 | flags = a_applied; |
113 | break; |
118 | break; |
114 | } |
119 | } |
115 | } |
120 | } |
116 | if (op->type == CONTAINER && ((op->env && op->env->container == op) || |
121 | if (op->type == CONTAINER && ((op->env && op->env->container == op) || (!op->env && QUERY_FLAG (op, FLAG_APPLIED)))) |
117 | (!op->env && QUERY_FLAG(op,FLAG_APPLIED)))) |
|
|
118 | flags |= F_OPEN; |
122 | flags |= F_OPEN; |
119 | |
123 | |
120 | if (QUERY_FLAG(op,FLAG_KNOWN_CURSED)) { |
124 | if (QUERY_FLAG (op, FLAG_KNOWN_CURSED)) |
|
|
125 | { |
121 | if(QUERY_FLAG(op,FLAG_DAMNED)) |
126 | if (QUERY_FLAG (op, FLAG_DAMNED)) |
122 | flags |= F_DAMNED; |
127 | flags |= F_DAMNED; |
123 | else if(QUERY_FLAG(op,FLAG_CURSED)) |
128 | else if (QUERY_FLAG (op, FLAG_CURSED)) |
124 | flags |= F_CURSED; |
129 | flags |= F_CURSED; |
125 | } |
130 | } |
126 | if (QUERY_FLAG(op,FLAG_KNOWN_MAGICAL) && !QUERY_FLAG(op,FLAG_IDENTIFIED)) |
131 | if (QUERY_FLAG (op, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (op, FLAG_IDENTIFIED)) |
127 | flags |= F_MAGIC; |
132 | flags |= F_MAGIC; |
128 | if (QUERY_FLAG(op,FLAG_UNPAID)) |
133 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
129 | flags |= F_UNPAID; |
134 | flags |= F_UNPAID; |
130 | if (QUERY_FLAG(op,FLAG_INV_LOCKED)) |
135 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
131 | flags |= F_LOCKED; |
136 | flags |= F_LOCKED; |
132 | |
137 | |
133 | return flags; |
138 | return flags; |
134 | } |
139 | } |
135 | |
140 | |
136 | /* Used in the send_look to put object head into SockList |
141 | /* Used in the send_look to put object head into SockList |
137 | * sl for socket ns. Need socket to know if we need to send |
142 | * sl for socket ns. Need socket to know if we need to send |
138 | * animation of face to the client. |
143 | * animation of face to the client. |
139 | */ |
144 | */ |
|
|
145 | static void |
140 | static void add_object_to_socklist(NewSocket *ns, SockList *sl, object *head) |
146 | add_object_to_socklist (NewSocket * ns, SockList * sl, object *head) |
141 | { |
147 | { |
142 | int flags, len, anim_speed; |
148 | int flags, len, anim_speed; |
143 | char item_n[MAX_BUF]; |
149 | char item_n[MAX_BUF]; |
144 | const char *item_p; |
150 | const char *item_p; |
145 | |
151 | |
146 | flags = query_flags (head); |
152 | flags = query_flags (head); |
147 | if (QUERY_FLAG(head, FLAG_NO_PICK)) |
153 | if (QUERY_FLAG (head, FLAG_NO_PICK)) |
148 | flags |= F_NOPICK; |
154 | flags |= F_NOPICK; |
149 | |
155 | |
150 | if (!(ns->faces_sent[head->face->number] & NS_FACESENT_FACE)) |
156 | if (!(ns->faces_sent[head->face->number] & NS_FACESENT_FACE)) |
151 | esrv_send_face(ns, head->face->number,0); |
157 | esrv_send_face (ns, head->face->number, 0); |
152 | |
158 | |
153 | if (QUERY_FLAG(head,FLAG_ANIMATE) && !ns->anims_sent[head->animation_id]) |
159 | if (QUERY_FLAG (head, FLAG_ANIMATE) && !ns->anims_sent[head->animation_id]) |
154 | esrv_send_animation(ns, head->animation_id); |
160 | esrv_send_animation (ns, head->animation_id); |
155 | |
161 | |
156 | SockList_AddInt(sl, head->count); |
162 | SockList_AddInt (sl, head->count); |
157 | SockList_AddInt(sl, flags); |
163 | SockList_AddInt (sl, flags); |
158 | SockList_AddInt(sl, QUERY_FLAG(head, FLAG_NO_PICK) ? -1 : WEIGHT(head)); |
164 | SockList_AddInt (sl, QUERY_FLAG (head, FLAG_NO_PICK) ? -1 : WEIGHT (head)); |
159 | SockList_AddInt(sl, head->face->number); |
165 | SockList_AddInt (sl, head->face->number); |
160 | |
166 | |
161 | if (!head->custom_name) { |
167 | if (!head->custom_name) |
|
|
168 | { |
162 | strncpy(item_n,query_base_name(head, 0),127); |
169 | strncpy (item_n, query_base_name (head, 0), 127); |
163 | item_n[127]=0; |
170 | item_n[127] = 0; |
164 | len=strlen(item_n); |
171 | len = strlen (item_n); |
165 | item_p=query_base_name(head, 1); |
172 | item_p = query_base_name (head, 1); |
166 | } else { |
173 | } |
|
|
174 | else |
|
|
175 | { |
167 | strncpy(item_n,head->custom_name,127); |
176 | strncpy (item_n, head->custom_name, 127); |
168 | item_n[127]=0; |
177 | item_n[127] = 0; |
169 | len=strlen(item_n); |
178 | len = strlen (item_n); |
170 | item_p=head->custom_name; |
179 | item_p = head->custom_name; |
171 | } |
180 | } |
172 | strncpy(item_n+len+1, item_p, 127); |
181 | strncpy (item_n + len + 1, item_p, 127); |
173 | item_n[254]=0; |
182 | item_n[254] = 0; |
174 | len += strlen(item_n+1+len) + 1; |
183 | len += strlen (item_n + 1 + len) + 1; |
175 | SockList_AddChar(sl, (char ) len); |
184 | SockList_AddChar (sl, (char) len); |
176 | memcpy(sl->buf+sl->len, item_n, len); |
185 | memcpy (sl->buf + sl->len, item_n, len); |
177 | sl->len += len; |
186 | sl->len += len; |
178 | |
187 | |
179 | SockList_AddShort(sl,head->animation_id); |
188 | SockList_AddShort (sl, head->animation_id); |
180 | anim_speed=0; |
189 | anim_speed = 0; |
181 | if (QUERY_FLAG(head,FLAG_ANIMATE)) { |
190 | if (QUERY_FLAG (head, FLAG_ANIMATE)) |
|
|
191 | { |
|
|
192 | if (head->anim_speed) |
182 | if (head->anim_speed) anim_speed=head->anim_speed; |
193 | anim_speed = head->anim_speed; |
|
|
194 | else |
|
|
195 | { |
|
|
196 | if (FABS (head->speed) < 0.001) |
|
|
197 | anim_speed = 255; |
|
|
198 | else if (FABS (head->speed) >= 1.0) |
|
|
199 | anim_speed = 1; |
183 | else { |
200 | else |
184 | if (FABS(head->speed)<0.001) anim_speed=255; |
|
|
185 | else if (FABS(head->speed)>=1.0) anim_speed=1; |
|
|
186 | else anim_speed = (int) (1.0/FABS(head->speed)); |
201 | anim_speed = (int) (1.0 / FABS (head->speed)); |
187 | } |
202 | } |
188 | if (anim_speed>255) anim_speed=255; |
203 | if (anim_speed > 255) |
|
|
204 | anim_speed = 255; |
189 | } |
205 | } |
190 | SockList_AddChar(sl, (char) anim_speed); |
206 | SockList_AddChar (sl, (char) anim_speed); |
191 | SockList_AddInt(sl, head->nrof); |
207 | SockList_AddInt (sl, head->nrof); |
192 | |
208 | |
193 | if (ns->itemcmd == 2) |
209 | if (ns->itemcmd == 2) |
194 | SockList_AddShort(sl, head->client_type); |
210 | SockList_AddShort (sl, head->client_type); |
195 | |
211 | |
196 | SET_FLAG(head, FLAG_CLIENT_SENT); |
212 | SET_FLAG (head, FLAG_CLIENT_SENT); |
197 | } |
213 | } |
198 | |
214 | |
199 | |
215 | |
200 | /** |
216 | /** |
201 | * Send the look window. Don't need to do animations here |
217 | * Send the look window. Don't need to do animations here |
202 | * This sends all the faces to the client, not just updates. This is |
218 | * This sends all the faces to the client, not just updates. This is |
203 | * because object ordering would otherwise be inconsistent |
219 | * because object ordering would otherwise be inconsistent |
204 | */ |
220 | */ |
205 | |
221 | |
|
|
222 | void |
206 | void esrv_draw_look(object *pl) |
223 | esrv_draw_look (object *pl) |
207 | { |
224 | { |
208 | object *tmp, *last; |
225 | object *tmp, *last; |
209 | int got_one=0,start_look=0, end_look=0; |
226 | int got_one = 0, start_look = 0, end_look = 0; |
210 | SockList sl; |
227 | SockList sl; |
211 | char buf[MAX_BUF]; |
228 | char buf[MAX_BUF]; |
212 | |
229 | |
213 | if (!pl->contr->socket.update_look) { |
230 | if (!pl->contr->socket.update_look) |
|
|
231 | { |
214 | LOG(llevDebug,"esrv_draw_look called when update_look was not set\n"); |
232 | LOG (llevDebug, "esrv_draw_look called when update_look was not set\n"); |
215 | return; |
233 | return; |
216 | } else { |
234 | } |
|
|
235 | else |
|
|
236 | { |
217 | pl->contr->socket.update_look=0; |
237 | pl->contr->socket.update_look = 0; |
218 | } |
238 | } |
219 | |
239 | |
220 | if(QUERY_FLAG(pl, FLAG_REMOVED) || pl->map == NULL || |
240 | if (QUERY_FLAG (pl, FLAG_REMOVED) || pl->map == NULL || pl->map->in_memory != MAP_IN_MEMORY || out_of_map (pl->map, pl->x, pl->y)) |
221 | pl->map->in_memory != MAP_IN_MEMORY || out_of_map(pl->map,pl->x,pl->y)) |
241 | return; |
222 | return; |
|
|
223 | |
242 | |
224 | for (tmp=get_map_ob(pl->map,pl->x,pl->y); tmp && tmp->above;tmp=tmp->above) ; |
243 | for (tmp = get_map_ob (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above); |
225 | |
244 | |
226 | sl.buf= (unsigned char *) malloc(MAXSOCKBUF); |
245 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
227 | |
246 | |
228 | Write_String_To_Socket(&pl->contr->socket, "delinv 0", strlen("delinv 0")); |
247 | Write_String_To_Socket (&pl->contr->socket, "delinv 0", strlen ("delinv 0")); |
229 | sprintf((char*)sl.buf,"item%d ", pl->contr->socket.itemcmd); |
248 | sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd); |
230 | sl.len=strlen((char*)sl.buf); |
249 | sl.len = strlen ((char *) sl.buf); |
231 | |
250 | |
232 | SockList_AddInt(&sl, 0); |
251 | SockList_AddInt (&sl, 0); |
233 | |
252 | |
234 | if (!(pl->contr->socket.faces_sent[empty_face->number]&NS_FACESENT_FACE)) |
253 | if (!(pl->contr->socket.faces_sent[empty_face->number] & NS_FACESENT_FACE)) |
235 | esrv_send_face(&pl->contr->socket, empty_face->number,0); |
254 | esrv_send_face (&pl->contr->socket, empty_face->number, 0); |
236 | |
255 | |
237 | if (pl->contr->socket.look_position) { |
256 | if (pl->contr->socket.look_position) |
|
|
257 | { |
238 | SockList_AddInt(&sl, 0x80000000 | (pl->contr->socket.look_position- NUM_LOOK_OBJECTS)); |
258 | SockList_AddInt (&sl, 0x80000000 | (pl->contr->socket.look_position - NUM_LOOK_OBJECTS)); |
239 | SockList_AddInt(&sl, 0); |
259 | SockList_AddInt (&sl, 0); |
240 | SockList_AddInt(&sl, (uint32) -1); |
260 | SockList_AddInt (&sl, (uint32) - 1); |
241 | SockList_AddInt(&sl, empty_face->number); |
261 | SockList_AddInt (&sl, empty_face->number); |
242 | sprintf(buf,"Click here to see %d previous items", NUM_LOOK_OBJECTS); |
262 | sprintf (buf, "Click here to see %d previous items", NUM_LOOK_OBJECTS); |
243 | add_stringlen_to_sockbuf(buf, &sl); |
263 | add_stringlen_to_sockbuf (buf, &sl); |
244 | SockList_AddShort(&sl,0); |
264 | SockList_AddShort (&sl, 0); |
245 | SockList_AddChar(&sl, 0); |
265 | SockList_AddChar (&sl, 0); |
246 | SockList_AddInt(&sl, 0); |
266 | SockList_AddInt (&sl, 0); |
247 | if (pl->contr->socket.itemcmd == 2) |
267 | if (pl->contr->socket.itemcmd == 2) |
248 | SockList_AddShort(&sl, 0); |
268 | SockList_AddShort (&sl, 0); |
249 | } |
269 | } |
250 | |
270 | |
251 | for (last=NULL; tmp!=last; tmp=tmp->below) { |
271 | for (last = NULL; tmp != last; tmp = tmp->below) |
|
|
272 | { |
252 | object *head; |
273 | object *head; |
253 | |
274 | |
254 | if (QUERY_FLAG(tmp, FLAG_IS_FLOOR) && !last) { |
275 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !last) |
|
|
276 | { |
255 | last = tmp->below; /* assumes double floor mode */ |
277 | last = tmp->below; /* assumes double floor mode */ |
256 | if (last && QUERY_FLAG(last, FLAG_IS_FLOOR)) |
278 | if (last && QUERY_FLAG (last, FLAG_IS_FLOOR)) |
257 | last = last->below; |
279 | last = last->below; |
258 | } |
280 | } |
259 | if (LOOK_OBJ(tmp)) { |
281 | if (LOOK_OBJ (tmp)) |
|
|
282 | { |
260 | if (++start_look < pl->contr->socket.look_position) continue; |
283 | if (++start_look < pl->contr->socket.look_position) |
|
|
284 | continue; |
261 | end_look++; |
285 | end_look++; |
262 | if (end_look > NUM_LOOK_OBJECTS) { |
286 | if (end_look > NUM_LOOK_OBJECTS) |
|
|
287 | { |
263 | /* What we basically do is make a 'fake' object - when the user applies it, |
288 | /* What we basically do is make a 'fake' object - when the user applies it, |
264 | * we notice the special tag the object has, and act accordingly. |
289 | * we notice the special tag the object has, and act accordingly. |
265 | */ |
290 | */ |
266 | SockList_AddInt(&sl, 0x80000000 | (pl->contr->socket.look_position+ NUM_LOOK_OBJECTS)); |
291 | SockList_AddInt (&sl, 0x80000000 | (pl->contr->socket.look_position + NUM_LOOK_OBJECTS)); |
267 | SockList_AddInt(&sl, 0); |
292 | SockList_AddInt (&sl, 0); |
268 | SockList_AddInt(&sl, (uint32) -1); |
293 | SockList_AddInt (&sl, (uint32) - 1); |
269 | SockList_AddInt(&sl, empty_face->number); |
294 | SockList_AddInt (&sl, empty_face->number); |
270 | sprintf(buf,"Click here to see next group of items"); |
295 | sprintf (buf, "Click here to see next group of items"); |
271 | add_stringlen_to_sockbuf(buf, &sl); |
296 | add_stringlen_to_sockbuf (buf, &sl); |
272 | SockList_AddShort(&sl,0); |
297 | SockList_AddShort (&sl, 0); |
273 | SockList_AddChar(&sl, 0); |
298 | SockList_AddChar (&sl, 0); |
274 | SockList_AddInt(&sl, 0); |
299 | SockList_AddInt (&sl, 0); |
275 | if (pl->contr->socket.itemcmd == 2) |
300 | if (pl->contr->socket.itemcmd == 2) |
276 | SockList_AddShort(&sl, 0); |
301 | SockList_AddShort (&sl, 0); |
277 | break; |
302 | break; |
278 | } |
303 | } |
|
|
304 | if (tmp->head) |
279 | if (tmp->head) head = tmp->head; |
305 | head = tmp->head; |
|
|
306 | else |
280 | else head = tmp; |
307 | head = tmp; |
281 | |
308 | |
282 | add_object_to_socklist(&pl->contr->socket, &sl, head); |
309 | add_object_to_socklist (&pl->contr->socket, &sl, head); |
283 | got_one++; |
310 | got_one++; |
284 | |
311 | |
285 | if (sl.len >= (MAXSOCKBUF-MAXITEMLEN)) { |
312 | if (sl.len >= (MAXSOCKBUF - MAXITEMLEN)) |
|
|
313 | { |
286 | Send_With_Handling(&pl->contr->socket, &sl); |
314 | Send_With_Handling (&pl->contr->socket, &sl); |
287 | sprintf((char*)sl.buf,"item%d ", pl->contr->socket.itemcmd); |
315 | sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd); |
288 | sl.len=strlen((char*)sl.buf); |
316 | sl.len = strlen ((char *) sl.buf); |
289 | SockList_AddInt(&sl, 0); |
317 | SockList_AddInt (&sl, 0); |
290 | got_one=0; |
318 | got_one = 0; |
291 | } |
319 | } |
292 | } /* If LOOK_OBJ() */ |
320 | } /* If LOOK_OBJ() */ |
293 | } |
321 | } |
294 | if (got_one) |
322 | if (got_one) |
295 | Send_With_Handling(&pl->contr->socket, &sl); |
323 | Send_With_Handling (&pl->contr->socket, &sl); |
296 | |
324 | |
297 | free(sl.buf); |
325 | free (sl.buf); |
298 | } |
326 | } |
299 | |
327 | |
300 | /** |
328 | /** |
301 | * Sends whole inventory. |
329 | * Sends whole inventory. |
302 | */ |
330 | */ |
|
|
331 | void |
303 | void esrv_send_inventory(object *pl, object *op) |
332 | esrv_send_inventory (object *pl, object *op) |
304 | { |
333 | { |
305 | object *tmp; |
334 | object *tmp; |
306 | int got_one=0; |
335 | int got_one = 0; |
307 | SockList sl; |
336 | SockList sl; |
308 | |
337 | |
309 | sl.buf= (unsigned char *) malloc(MAXSOCKBUF); |
338 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
310 | |
339 | |
311 | sprintf((char*)sl.buf,"delinv %d", op->count); |
340 | sprintf ((char *) sl.buf, "delinv %d", op->count); |
312 | sl.len=strlen((char*)sl.buf); |
341 | sl.len = strlen ((char *) sl.buf); |
313 | Send_With_Handling(&pl->contr->socket, &sl); |
342 | Send_With_Handling (&pl->contr->socket, &sl); |
314 | |
343 | |
315 | sprintf((char*)sl.buf,"item%d ", pl->contr->socket.itemcmd); |
344 | sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd); |
316 | sl.len=strlen((char*)sl.buf); |
345 | sl.len = strlen ((char *) sl.buf); |
317 | |
346 | |
318 | SockList_AddInt(&sl, op->count); |
347 | SockList_AddInt (&sl, op->count); |
319 | |
348 | |
320 | for (tmp=op->inv; tmp; tmp=tmp->below) { |
349 | for (tmp = op->inv; tmp; tmp = tmp->below) |
|
|
350 | { |
321 | object *head; |
351 | object *head; |
322 | |
352 | |
|
|
353 | if (tmp->head) |
323 | if (tmp->head) head = tmp->head; |
354 | head = tmp->head; |
|
|
355 | else |
324 | else head = tmp; |
356 | head = tmp; |
325 | |
357 | |
326 | if (LOOK_OBJ(head)) { |
358 | if (LOOK_OBJ (head)) |
|
|
359 | { |
327 | add_object_to_socklist(&pl->contr->socket, &sl, head); |
360 | add_object_to_socklist (&pl->contr->socket, &sl, head); |
328 | |
361 | |
329 | got_one++; |
362 | got_one++; |
330 | |
363 | |
331 | /* IT is possible for players to accumulate a huge amount of |
364 | /* IT is possible for players to accumulate a huge amount of |
332 | * items (especially with some of the bags out there) to |
365 | * items (especially with some of the bags out there) to |
333 | * overflow the buffer. IF so, send multiple item commands. |
366 | * overflow the buffer. IF so, send multiple item commands. |
334 | */ |
367 | */ |
335 | if (sl.len >= (MAXSOCKBUF-MAXITEMLEN)) { |
368 | if (sl.len >= (MAXSOCKBUF - MAXITEMLEN)) |
|
|
369 | { |
336 | Send_With_Handling(&pl->contr->socket, &sl); |
370 | Send_With_Handling (&pl->contr->socket, &sl); |
337 | sprintf((char*)sl.buf,"item%d ", pl->contr->socket.itemcmd); |
371 | sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd); |
338 | sl.len=strlen((char*)sl.buf); |
372 | sl.len = strlen ((char *) sl.buf); |
339 | SockList_AddInt(&sl, op->count); |
373 | SockList_AddInt (&sl, op->count); |
340 | got_one=0; |
374 | got_one = 0; |
341 | } |
375 | } |
342 | } /* If LOOK_OBJ() */ |
376 | } /* If LOOK_OBJ() */ |
343 | } |
377 | } |
344 | if (got_one) |
378 | if (got_one) |
345 | Send_With_Handling(&pl->contr->socket, &sl); |
379 | Send_With_Handling (&pl->contr->socket, &sl); |
346 | free(sl.buf); |
380 | free (sl.buf); |
347 | } |
381 | } |
348 | |
382 | |
349 | /** |
383 | /** |
350 | * Updates object *op for player *pl. |
384 | * Updates object *op for player *pl. |
351 | * |
385 | * |
352 | * flags is a list of values to update |
386 | * flags is a list of values to update |
353 | * to the client (as defined in newclient.h - might as well use the |
387 | * to the client (as defined in newclient.h - might as well use the |
354 | * same value both places. |
388 | * same value both places. |
355 | */ |
389 | */ |
356 | |
390 | |
|
|
391 | void |
357 | void esrv_update_item(int flags, object *pl, object *op) |
392 | esrv_update_item (int flags, object *pl, object *op) |
358 | { |
393 | { |
359 | SockList sl; |
394 | SockList sl; |
360 | |
395 | |
361 | /* If we have a request to send the player item, skip a few checks. */ |
396 | /* If we have a request to send the player item, skip a few checks. */ |
362 | if (op!=pl) { |
397 | if (op != pl) |
|
|
398 | { |
363 | if (! LOOK_OBJ(op)) |
399 | if (!LOOK_OBJ (op)) |
364 | return; |
400 | return; |
365 | /* we remove the check for op->env, because in theory, the object |
401 | /* we remove the check for op->env, because in theory, the object |
366 | * is hopefully in the same place, so the client should preserve |
402 | * is hopefully in the same place, so the client should preserve |
367 | * order. |
403 | * order. |
368 | */ |
404 | */ |
369 | } |
405 | } |
370 | if (!QUERY_FLAG(op, FLAG_CLIENT_SENT)) { |
406 | if (!QUERY_FLAG (op, FLAG_CLIENT_SENT)) |
|
|
407 | { |
371 | /* FLAG_CLIENT_SENT is debug only. We are using it to see where |
408 | /* FLAG_CLIENT_SENT is debug only. We are using it to see where |
372 | * this is happening - we can set a breakpoint here in the debugger |
409 | * this is happening - we can set a breakpoint here in the debugger |
373 | * and track back the call. |
410 | * and track back the call. |
374 | */ |
411 | */ |
375 | LOG(llevDebug,"We have not sent item %s (%d)\n", &op->name, op->count); |
412 | LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count); |
376 | } |
413 | } |
377 | sl.buf= (unsigned char *) malloc(MAXSOCKBUF); |
414 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
378 | |
415 | |
379 | strcpy((char*)sl.buf,"upditem "); |
416 | strcpy ((char *) sl.buf, "upditem "); |
380 | sl.len=strlen((char*)sl.buf); |
417 | sl.len = strlen ((char *) sl.buf); |
381 | |
418 | |
382 | SockList_AddChar(&sl, (char) flags); |
419 | SockList_AddChar (&sl, (char) flags); |
383 | |
420 | |
384 | if (op->head) op=op->head; |
421 | if (op->head) |
|
|
422 | op = op->head; |
385 | |
423 | |
386 | SockList_AddInt(&sl, op->count); |
424 | SockList_AddInt (&sl, op->count); |
387 | |
425 | |
388 | if (flags & UPD_LOCATION) |
426 | if (flags & UPD_LOCATION) |
389 | SockList_AddInt(&sl, op->env? op->env->count:0); |
427 | SockList_AddInt (&sl, op->env ? op->env->count : 0); |
390 | |
428 | |
391 | if (flags & UPD_FLAGS) |
429 | if (flags & UPD_FLAGS) |
392 | SockList_AddInt(&sl, query_flags(op)); |
430 | SockList_AddInt (&sl, query_flags (op)); |
393 | |
431 | |
394 | if (flags & UPD_WEIGHT) { |
432 | if (flags & UPD_WEIGHT) |
|
|
433 | { |
395 | sint32 weight = WEIGHT(op); |
434 | sint32 weight = WEIGHT (op); |
396 | |
435 | |
397 | SockList_AddInt(&sl, QUERY_FLAG(op, FLAG_NO_PICK) ? -1 : weight); |
436 | SockList_AddInt (&sl, QUERY_FLAG (op, FLAG_NO_PICK) ? -1 : weight); |
398 | if (pl == op) { |
437 | if (pl == op) |
|
|
438 | { |
399 | op->contr->last_weight = weight; |
439 | op->contr->last_weight = weight; |
400 | } |
440 | } |
401 | } |
441 | } |
402 | |
442 | |
403 | if (flags & UPD_FACE) { |
443 | if (flags & UPD_FACE) |
|
|
444 | { |
404 | if (!(pl->contr->socket.faces_sent[op->face->number] & NS_FACESENT_FACE)) |
445 | if (!(pl->contr->socket.faces_sent[op->face->number] & NS_FACESENT_FACE)) |
405 | esrv_send_face(&pl->contr->socket, op->face->number,0); |
446 | esrv_send_face (&pl->contr->socket, op->face->number, 0); |
406 | SockList_AddInt(&sl, op->face->number); |
447 | SockList_AddInt (&sl, op->face->number); |
407 | } |
448 | } |
408 | if (flags & UPD_NAME) { |
449 | if (flags & UPD_NAME) |
|
|
450 | { |
409 | int len; |
451 | int len; |
410 | const char *item_p; |
452 | const char *item_p; |
411 | char item_n[MAX_BUF]; |
453 | char item_n[MAX_BUF]; |
412 | |
454 | |
413 | if (!op->custom_name) { |
455 | if (!op->custom_name) |
|
|
456 | { |
414 | strncpy(item_n,query_base_name(op, 0),127); |
457 | strncpy (item_n, query_base_name (op, 0), 127); |
415 | item_n[127]=0; |
458 | item_n[127] = 0; |
416 | len=strlen(item_n); |
459 | len = strlen (item_n); |
417 | item_p=query_base_name(op, 1); |
460 | item_p = query_base_name (op, 1); |
|
|
461 | } |
|
|
462 | else |
418 | } |
463 | { |
419 | else { |
|
|
420 | strncpy(item_n,op->custom_name,127); |
464 | strncpy (item_n, op->custom_name, 127); |
421 | item_n[127]=0; |
465 | item_n[127] = 0; |
422 | len=strlen(item_n); |
466 | len = strlen (item_n); |
423 | item_p=op->custom_name; |
467 | item_p = op->custom_name; |
424 | } |
468 | } |
425 | |
469 | |
426 | strncpy(item_n+len+1, item_p, 127); |
470 | strncpy (item_n + len + 1, item_p, 127); |
427 | item_n[254]=0; |
471 | item_n[254] = 0; |
428 | len += strlen(item_n+1+len) + 1; |
472 | len += strlen (item_n + 1 + len) + 1; |
429 | SockList_AddChar(&sl, (char)len); |
473 | SockList_AddChar (&sl, (char) len); |
430 | memcpy(sl.buf+sl.len, item_n, len); |
474 | memcpy (sl.buf + sl.len, item_n, len); |
431 | sl.len += len; |
475 | sl.len += len; |
432 | } |
476 | } |
433 | if (flags & UPD_ANIM) |
477 | if (flags & UPD_ANIM) |
434 | SockList_AddShort(&sl,op->animation_id); |
478 | SockList_AddShort (&sl, op->animation_id); |
435 | |
479 | |
436 | if (flags & UPD_ANIMSPEED) { |
480 | if (flags & UPD_ANIMSPEED) |
|
|
481 | { |
437 | int anim_speed=0; |
482 | int anim_speed = 0; |
|
|
483 | |
438 | if (QUERY_FLAG(op,FLAG_ANIMATE)) { |
484 | if (QUERY_FLAG (op, FLAG_ANIMATE)) |
|
|
485 | { |
|
|
486 | if (op->anim_speed) |
439 | if (op->anim_speed) anim_speed=op->anim_speed; |
487 | anim_speed = op->anim_speed; |
|
|
488 | else |
|
|
489 | { |
|
|
490 | if (FABS (op->speed) < 0.001) |
|
|
491 | anim_speed = 255; |
|
|
492 | else if (FABS (op->speed) >= 1.0) |
|
|
493 | anim_speed = 1; |
440 | else { |
494 | else |
441 | if (FABS(op->speed)<0.001) anim_speed=255; |
|
|
442 | else if (FABS(op->speed)>=1.0) anim_speed=1; |
|
|
443 | else anim_speed = (int) (1.0/FABS(op->speed)); |
495 | anim_speed = (int) (1.0 / FABS (op->speed)); |
444 | } |
496 | } |
445 | if (anim_speed>255) anim_speed=255; |
497 | if (anim_speed > 255) |
|
|
498 | anim_speed = 255; |
446 | } |
499 | } |
447 | SockList_AddChar(&sl, (char)anim_speed); |
500 | SockList_AddChar (&sl, (char) anim_speed); |
448 | } |
501 | } |
449 | if (flags & UPD_NROF) |
502 | if (flags & UPD_NROF) |
450 | SockList_AddInt(&sl, op->nrof); |
503 | SockList_AddInt (&sl, op->nrof); |
451 | |
504 | |
452 | Send_With_Handling(&pl->contr->socket, &sl); |
505 | Send_With_Handling (&pl->contr->socket, &sl); |
453 | free(sl.buf); |
506 | free (sl.buf); |
454 | } |
507 | } |
455 | |
508 | |
456 | /** |
509 | /** |
457 | * Sends item's info to player. |
510 | * Sends item's info to player. |
458 | */ |
511 | */ |
|
|
512 | void |
459 | void esrv_send_item(object *pl, object*op) |
513 | esrv_send_item (object *pl, object *op) |
460 | { |
514 | { |
461 | SockList sl; |
515 | SockList sl; |
462 | |
516 | |
463 | /* If this is not the player object, do some more checks */ |
517 | /* If this is not the player object, do some more checks */ |
464 | if (op!=pl) { |
518 | if (op != pl) |
|
|
519 | { |
465 | /* We only send 'visibile' objects to the client */ |
520 | /* We only send 'visibile' objects to the client */ |
466 | if (! LOOK_OBJ(op)) |
521 | if (!LOOK_OBJ (op)) |
467 | return; |
522 | return; |
468 | /* if the item is on the ground, mark that the look needs to |
523 | /* if the item is on the ground, mark that the look needs to |
469 | * be updated. |
524 | * be updated. |
470 | */ |
525 | */ |
471 | if (!op->env) { |
526 | if (!op->env) |
|
|
527 | { |
472 | pl->contr->socket.update_look=1; |
528 | pl->contr->socket.update_look = 1; |
473 | return; |
529 | return; |
474 | } |
530 | } |
475 | } |
531 | } |
476 | |
532 | |
477 | sl.buf= (unsigned char *) malloc(MAXSOCKBUF); |
533 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
478 | |
534 | |
479 | sprintf((char*)sl.buf,"item%d ", pl->contr->socket.itemcmd); |
535 | sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd); |
480 | sl.len=strlen((char*)sl.buf); |
536 | sl.len = strlen ((char *) sl.buf); |
481 | |
537 | |
482 | if (op->head) op=op->head; |
538 | if (op->head) |
|
|
539 | op = op->head; |
483 | |
540 | |
484 | SockList_AddInt(&sl, op->env? op->env->count:0); |
541 | SockList_AddInt (&sl, op->env ? op->env->count : 0); |
485 | |
542 | |
486 | add_object_to_socklist(&pl->contr->socket, &sl, op); |
543 | add_object_to_socklist (&pl->contr->socket, &sl, op); |
487 | |
544 | |
488 | Send_With_Handling(&pl->contr->socket, &sl); |
545 | Send_With_Handling (&pl->contr->socket, &sl); |
489 | SET_FLAG(op, FLAG_CLIENT_SENT); |
546 | SET_FLAG (op, FLAG_CLIENT_SENT); |
490 | free(sl.buf); |
547 | free (sl.buf); |
491 | } |
548 | } |
492 | |
549 | |
493 | /** |
550 | /** |
494 | * Tells the client to delete an item. Uses the item |
551 | * Tells the client to delete an item. Uses the item |
495 | * command with a -1 location. |
552 | * command with a -1 location. |
496 | */ |
553 | */ |
497 | |
554 | |
|
|
555 | void |
498 | void esrv_del_item(player *pl, int tag) |
556 | esrv_del_item (player *pl, int tag) |
499 | { |
557 | { |
500 | SockList sl; |
558 | SockList sl; |
501 | |
559 | |
502 | sl.buf= (unsigned char *) malloc(MAXSOCKBUF); |
560 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
503 | |
561 | |
504 | strcpy((char*)sl.buf,"delitem "); |
562 | strcpy ((char *) sl.buf, "delitem "); |
505 | sl.len=strlen((char*)sl.buf); |
563 | sl.len = strlen ((char *) sl.buf); |
506 | SockList_AddInt(&sl, tag); |
564 | SockList_AddInt (&sl, tag); |
507 | |
565 | |
508 | Send_With_Handling(&pl->socket, &sl); |
566 | Send_With_Handling (&pl->socket, &sl); |
509 | free(sl.buf); |
567 | free (sl.buf); |
510 | } |
568 | } |
511 | |
569 | |
512 | |
570 | |
513 | /******************************************************************************* |
571 | /******************************************************************************* |
514 | * |
572 | * |
… | |
… | |
519 | /** |
577 | /** |
520 | * Takes a player and object count (tag) and returns the actual object |
578 | * Takes a player and object count (tag) and returns the actual object |
521 | * pointer, or null if it can't be found. |
579 | * pointer, or null if it can't be found. |
522 | */ |
580 | */ |
523 | |
581 | |
|
|
582 | object * |
524 | object *esrv_get_ob_from_count(object *pl, tag_t count) |
583 | esrv_get_ob_from_count (object *pl, tag_t count) |
525 | { |
584 | { |
526 | object *op, *tmp; |
585 | object *op, *tmp; |
527 | |
586 | |
528 | if (pl->count == count) |
587 | if (pl->count == count) |
529 | return pl; |
588 | return pl; |
530 | |
589 | |
531 | for(op = pl->inv; op; op = op->below) |
590 | for (op = pl->inv; op; op = op->below) |
532 | if (op->count == count) |
591 | if (op->count == count) |
533 | return op; |
592 | return op; |
534 | else if (op->type == CONTAINER && pl->container == op) |
593 | else if (op->type == CONTAINER && pl->container == op) |
535 | for(tmp = op->inv; tmp; tmp = tmp->below) |
594 | for (tmp = op->inv; tmp; tmp = tmp->below) |
536 | if (tmp->count == count) |
595 | if (tmp->count == count) |
537 | return tmp; |
596 | return tmp; |
538 | |
597 | |
539 | for(op = get_map_ob (pl->map, pl->x, pl->y); op; op = op->above) |
598 | for (op = get_map_ob (pl->map, pl->x, pl->y); op; op = op->above) |
540 | if (op->head != NULL && op->head->count == count) |
599 | if (op->head != NULL && op->head->count == count) |
541 | return op; |
600 | return op; |
542 | else if (op->count == count) |
601 | else if (op->count == count) |
543 | return op; |
602 | return op; |
544 | else if (op->type == CONTAINER && pl->container == op) |
603 | else if (op->type == CONTAINER && pl->container == op) |
545 | for(tmp = op->inv; tmp; tmp = tmp->below) |
604 | for (tmp = op->inv; tmp; tmp = tmp->below) |
546 | if (tmp->count == count) |
605 | if (tmp->count == count) |
547 | return tmp; |
606 | return tmp; |
548 | |
607 | |
549 | return NULL; |
608 | return NULL; |
550 | } |
609 | } |
551 | |
610 | |
552 | |
611 | |
553 | /** Client wants to examine some object. So lets do so. */ |
612 | /** Client wants to examine some object. So lets do so. */ |
|
|
613 | void |
554 | void ExamineCmd(char *buf, int len,player *pl) |
614 | ExamineCmd (char *buf, int len, player *pl) |
555 | { |
615 | { |
556 | long tag = atoi(buf); |
616 | long tag = atoi (buf); |
557 | object *op = esrv_get_ob_from_count(pl->ob, tag); |
617 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
558 | |
618 | |
559 | if (!op) { |
619 | if (!op) |
|
|
620 | { |
560 | LOG(llevDebug, "Player '%s' tried to examine the unknown object (%ld)\n", &pl->ob->name, tag); |
621 | LOG (llevDebug, "Player '%s' tried to examine the unknown object (%ld)\n", &pl->ob->name, tag); |
561 | return; |
622 | return; |
562 | } |
623 | } |
563 | examine (pl->ob, op); |
624 | examine (pl->ob, op); |
564 | } |
625 | } |
565 | |
626 | |
566 | /** Client wants to apply some object. Lets do so. */ |
627 | /** Client wants to apply some object. Lets do so. */ |
|
|
628 | void |
567 | void ApplyCmd(char *buf, int len,player *pl) |
629 | ApplyCmd (char *buf, int len, player *pl) |
568 | { |
630 | { |
569 | uint32 tag = atoi(buf); |
631 | uint32 tag = atoi (buf); |
570 | object *op = esrv_get_ob_from_count(pl->ob, tag); |
632 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
571 | |
633 | |
572 | /* sort of a hack, but if the player saves and the player then manually |
634 | /* sort of a hack, but if the player saves and the player then manually |
573 | * applies a savebed (or otherwise tries to do stuff), we run into trouble. |
635 | * applies a savebed (or otherwise tries to do stuff), we run into trouble. |
574 | */ |
636 | */ |
575 | if (QUERY_FLAG(pl->ob, FLAG_REMOVED)) return; |
637 | if (QUERY_FLAG (pl->ob, FLAG_REMOVED)) |
|
|
638 | return; |
576 | |
639 | |
577 | /* If the high bit is set, player applied a pseudo object. */ |
640 | /* If the high bit is set, player applied a pseudo object. */ |
578 | if (tag & 0x80000000) { |
641 | if (tag & 0x80000000) |
|
|
642 | { |
579 | pl->socket.look_position = tag & 0x7fffffff; |
643 | pl->socket.look_position = tag & 0x7fffffff; |
580 | pl->socket.update_look = 1; |
644 | pl->socket.update_look = 1; |
581 | return; |
645 | return; |
582 | } |
646 | } |
583 | |
647 | |
584 | if (!op) { |
648 | if (!op) |
|
|
649 | { |
585 | LOG(llevDebug, "Player '%s' tried to apply the unknown object (%d)\n", &pl->ob->name, tag); |
650 | LOG (llevDebug, "Player '%s' tried to apply the unknown object (%d)\n", &pl->ob->name, tag); |
586 | return; |
651 | return; |
587 | } |
652 | } |
588 | player_apply (pl->ob, op, 0, 0); |
653 | player_apply (pl->ob, op, 0, 0); |
589 | } |
654 | } |
590 | |
655 | |
591 | /** Client wants to apply some object. Lets do so. */ |
656 | /** Client wants to apply some object. Lets do so. */ |
|
|
657 | void |
592 | void LockItem(uint8 *data, int len,player *pl) |
658 | LockItem (uint8 * data, int len, player *pl) |
593 | { |
659 | { |
594 | int flag, tag; |
660 | int flag, tag; |
595 | object *op; |
661 | object *op; |
596 | |
662 | |
597 | flag = data[0]; |
663 | flag = data[0]; |
598 | tag = GetInt_String(data+1); |
664 | tag = GetInt_String (data + 1); |
599 | op = esrv_get_ob_from_count(pl->ob, tag); |
665 | op = esrv_get_ob_from_count (pl->ob, tag); |
600 | |
666 | |
601 | if (!op) { |
667 | if (!op) |
|
|
668 | { |
602 | new_draw_info(NDI_UNIQUE, 0, pl->ob,"Could not find object to lock/unlock"); |
669 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock"); |
603 | return; |
670 | return; |
604 | } |
671 | } |
605 | if (!flag) |
672 | if (!flag) |
606 | CLEAR_FLAG(op,FLAG_INV_LOCKED); |
673 | CLEAR_FLAG (op, FLAG_INV_LOCKED); |
607 | else |
674 | else |
608 | SET_FLAG(op,FLAG_INV_LOCKED); |
675 | SET_FLAG (op, FLAG_INV_LOCKED); |
609 | esrv_update_item(UPD_FLAGS, pl->ob, op); |
676 | esrv_update_item (UPD_FLAGS, pl->ob, op); |
610 | } |
677 | } |
611 | |
678 | |
612 | /** Client wants to apply some object. Lets do so. */ |
679 | /** Client wants to apply some object. Lets do so. */ |
|
|
680 | void |
613 | void MarkItem(uint8 *data, int len,player *pl) |
681 | MarkItem (uint8 * data, int len, player *pl) |
614 | { |
682 | { |
615 | int tag; |
683 | int tag; |
616 | object *op; |
684 | object *op; |
617 | |
685 | |
618 | tag = GetInt_String(data); |
686 | tag = GetInt_String (data); |
619 | op = esrv_get_ob_from_count(pl->ob, tag); |
687 | op = esrv_get_ob_from_count (pl->ob, tag); |
620 | if (!op) { |
688 | if (!op) |
|
|
689 | { |
621 | new_draw_info(NDI_UNIQUE, 0, pl->ob,"Could not find object to mark"); |
690 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark"); |
622 | return; |
691 | return; |
623 | } |
692 | } |
624 | pl->mark = op; |
693 | pl->mark = op; |
625 | pl->mark_count = op->count; |
694 | pl->mark_count = op->count; |
626 | new_draw_info_format(NDI_UNIQUE, 0, pl->ob, "Marked item %s", query_name(op)); |
695 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Marked item %s", query_name (op)); |
627 | } |
696 | } |
628 | |
697 | |
629 | |
698 | |
630 | /** |
699 | /** |
631 | * look_at prints items on the specified square. |
700 | * look_at prints items on the specified square. |
632 | * |
701 | * |
633 | * [ removed EARTHWALL check and added check for containers inventory. |
702 | * [ removed EARTHWALL check and added check for containers inventory. |
634 | * Tero.Haatanen@lut.fi ] |
703 | * Tero.Haatanen@lut.fi ] |
635 | */ |
704 | */ |
|
|
705 | void |
636 | void look_at(object *op,int dx,int dy) { |
706 | look_at (object *op, int dx, int dy) |
|
|
707 | { |
637 | object *tmp; |
708 | object *tmp; |
638 | int flag=0; |
709 | int flag = 0; |
639 | sint16 x,y; |
710 | sint16 x, y; |
640 | mapstruct *m; |
711 | mapstruct *m; |
641 | |
712 | |
642 | x = op->x + dx; |
713 | x = op->x + dx; |
643 | y = op->y + dy; |
714 | y = op->y + dy; |
644 | |
715 | |
645 | if (out_of_map(op->map, x, y)) return; |
716 | if (out_of_map (op->map, x, y)) |
|
|
717 | return; |
646 | |
718 | |
647 | m = get_map_from_coord(op->map, &x, &y); |
719 | m = get_map_from_coord (op->map, &x, &y); |
648 | if (!m) return; |
720 | if (!m) |
|
|
721 | return; |
649 | |
722 | |
650 | for(tmp=get_map_ob(m, x ,y);tmp!=NULL&&tmp->above!=NULL; |
723 | for (tmp = get_map_ob (m, x, y); tmp != NULL && tmp->above != NULL; tmp = tmp->above); |
651 | tmp=tmp->above); |
|
|
652 | |
724 | |
653 | for ( ; tmp != NULL; tmp=tmp->below ) { |
725 | for (; tmp != NULL; tmp = tmp->below) |
|
|
726 | { |
654 | if (tmp->invisible && !QUERY_FLAG(op, FLAG_WIZ)) continue; |
727 | if (tmp->invisible && !QUERY_FLAG (op, FLAG_WIZ)) |
|
|
728 | continue; |
655 | |
729 | |
656 | if(!flag) { |
730 | if (!flag) |
|
|
731 | { |
657 | if(dx||dy) |
732 | if (dx || dy) |
658 | new_draw_info(NDI_UNIQUE, 0,op,"There you see:"); |
733 | new_draw_info (NDI_UNIQUE, 0, op, "There you see:"); |
659 | else { |
734 | else |
|
|
735 | { |
660 | clear_win_info(op); |
736 | clear_win_info (op); |
661 | new_draw_info(NDI_UNIQUE, 0,op,"You see:"); |
737 | new_draw_info (NDI_UNIQUE, 0, op, "You see:"); |
662 | } |
738 | } |
663 | flag=1; |
739 | flag = 1; |
664 | } |
740 | } |
665 | |
741 | |
666 | if (QUERY_FLAG(op, FLAG_WIZ)) |
742 | if (QUERY_FLAG (op, FLAG_WIZ)) |
667 | new_draw_info_format(NDI_UNIQUE,0, op, "- %s (%d).",query_name(tmp),tmp->count); |
743 | new_draw_info_format (NDI_UNIQUE, 0, op, "- %s (%d).", query_name (tmp), tmp->count); |
668 | else |
744 | else |
669 | new_draw_info_format(NDI_UNIQUE,0, op, "- %s.",query_name(tmp)); |
745 | new_draw_info_format (NDI_UNIQUE, 0, op, "- %s.", query_name (tmp)); |
670 | |
746 | |
671 | if (((tmp->inv!=NULL || (tmp->head && tmp->head->inv)) && |
747 | if (((tmp->inv != NULL || (tmp->head && tmp->head->inv)) && |
672 | (tmp->type != CONTAINER && tmp->type!=FLESH)) || QUERY_FLAG(op, FLAG_WIZ)) |
748 | (tmp->type != CONTAINER && tmp->type != FLESH)) || QUERY_FLAG (op, FLAG_WIZ)) |
673 | inventory(op,tmp->head==NULL?tmp:tmp->head); |
749 | inventory (op, tmp->head == NULL ? tmp : tmp->head); |
674 | |
750 | |
675 | if(QUERY_FLAG(tmp, FLAG_IS_FLOOR)&&!QUERY_FLAG(op, FLAG_WIZ)) /* don't continue under the floor */ |
751 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !QUERY_FLAG (op, FLAG_WIZ)) /* don't continue under the floor */ |
676 | break; |
752 | break; |
677 | } |
753 | } |
678 | |
754 | |
679 | if(!flag) { |
755 | if (!flag) |
|
|
756 | { |
680 | if(dx||dy) |
757 | if (dx || dy) |
681 | new_draw_info(NDI_UNIQUE, 0,op,"You see nothing there."); |
758 | new_draw_info (NDI_UNIQUE, 0, op, "You see nothing there."); |
682 | else |
759 | else |
683 | new_draw_info(NDI_UNIQUE, 0,op,"You see nothing."); |
760 | new_draw_info (NDI_UNIQUE, 0, op, "You see nothing."); |
684 | } |
761 | } |
685 | } |
762 | } |
686 | |
763 | |
687 | |
764 | |
688 | |
765 | |
689 | /** Client wants to look at some object. Lets do so. */ |
766 | /** Client wants to look at some object. Lets do so. */ |
|
|
767 | void |
690 | void LookAt(char *buf, int len,player *pl) |
768 | LookAt (char *buf, int len, player *pl) |
691 | { |
769 | { |
692 | int dx, dy; |
770 | int dx, dy; |
693 | char *cp; |
771 | char *cp; |
694 | |
772 | |
695 | dx=atoi(buf); |
773 | dx = atoi (buf); |
696 | if (!(cp=strchr(buf,' '))) { |
774 | if (!(cp = strchr (buf, ' '))) |
|
|
775 | { |
|
|
776 | return; |
|
|
777 | } |
|
|
778 | dy = atoi (cp); |
|
|
779 | |
|
|
780 | if (FABS (dx) > pl->socket.mapx / 2 || FABS (dy) > pl->socket.mapy / 2) |
|
|
781 | return; |
|
|
782 | |
|
|
783 | if (pl->blocked_los[dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]) |
|
|
784 | return; |
|
|
785 | |
|
|
786 | look_at (pl->ob, dx, dy); |
|
|
787 | } |
|
|
788 | |
|
|
789 | /** Move an object to a new location */ |
|
|
790 | void |
|
|
791 | esrv_move_object (object *pl, tag_t to, tag_t tag, long nrof) |
|
|
792 | { |
|
|
793 | object *op, *env; |
|
|
794 | |
|
|
795 | op = esrv_get_ob_from_count (pl, tag); |
|
|
796 | if (!op) |
|
|
797 | { |
|
|
798 | LOG (llevDebug, "Player '%s' tried to move an unknown object (%ld)\n", &pl->name, tag); |
|
|
799 | return; |
|
|
800 | } |
|
|
801 | |
|
|
802 | if (!to) |
|
|
803 | { /* drop it to the ground */ |
|
|
804 | |
|
|
805 | /* LOG(llevDebug, "Drop it on the ground.\n");*/ |
|
|
806 | |
|
|
807 | if (op->map && !op->env) |
|
|
808 | { |
|
|
809 | |
|
|
810 | /* LOG(llevDebug,"Dropping object to ground that is already on ground\n");*/ |
|
|
811 | return; |
|
|
812 | } |
|
|
813 | /* If it is an active container, then we should drop all objects |
|
|
814 | * in the container and not the container itself. |
|
|
815 | */ |
|
|
816 | if (op->inv && QUERY_FLAG (op, FLAG_APPLIED)) |
|
|
817 | { |
|
|
818 | object *current, *next; |
|
|
819 | |
|
|
820 | for (current = op->inv; current != NULL; current = next) |
|
|
821 | { |
|
|
822 | next = current->below; |
|
|
823 | drop_object (pl, current, 0); |
|
|
824 | } |
|
|
825 | esrv_update_item (UPD_WEIGHT, pl, op); |
|
|
826 | } |
|
|
827 | else |
|
|
828 | { |
|
|
829 | drop_object (pl, op, nrof); |
|
|
830 | } |
|
|
831 | return; |
|
|
832 | } |
|
|
833 | else if (to == pl->count) |
|
|
834 | { /* pick it up to the inventory */ |
|
|
835 | /* return if player has already picked it up */ |
|
|
836 | if (op->env == pl) |
697 | return; |
837 | return; |
698 | } |
|
|
699 | dy=atoi(cp); |
|
|
700 | |
838 | |
701 | if (FABS(dx) > pl->socket.mapx / 2 || FABS(dy) > pl->socket.mapy / 2) |
|
|
702 | return; |
|
|
703 | |
|
|
704 | if(pl->blocked_los[dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]) |
|
|
705 | return; |
|
|
706 | |
|
|
707 | look_at(pl->ob, dx, dy); |
|
|
708 | } |
|
|
709 | |
|
|
710 | /** Move an object to a new location */ |
|
|
711 | void esrv_move_object (object *pl, tag_t to, tag_t tag, long nrof) |
|
|
712 | { |
|
|
713 | object *op, *env; |
|
|
714 | |
|
|
715 | op = esrv_get_ob_from_count(pl, tag); |
|
|
716 | if (!op) { |
|
|
717 | LOG(llevDebug, "Player '%s' tried to move an unknown object (%ld)\n", &pl->name, tag); |
|
|
718 | return; |
|
|
719 | } |
|
|
720 | |
|
|
721 | if (!to) { /* drop it to the ground */ |
|
|
722 | /* LOG(llevDebug, "Drop it on the ground.\n");*/ |
|
|
723 | |
|
|
724 | if (op->map && !op->env) { |
|
|
725 | /* LOG(llevDebug,"Dropping object to ground that is already on ground\n");*/ |
|
|
726 | return; |
|
|
727 | } |
|
|
728 | /* If it is an active container, then we should drop all objects |
|
|
729 | * in the container and not the container itself. |
|
|
730 | */ |
|
|
731 | if (op->inv && QUERY_FLAG(op, FLAG_APPLIED)) { |
|
|
732 | object *current, *next; |
|
|
733 | for (current=op->inv; current!=NULL; current=next) { |
|
|
734 | next=current->below; |
|
|
735 | drop_object(pl, current, 0); |
|
|
736 | } |
|
|
737 | esrv_update_item(UPD_WEIGHT, pl, op); |
|
|
738 | } |
|
|
739 | else { |
|
|
740 | drop_object (pl, op, nrof); |
|
|
741 | } |
|
|
742 | return; |
|
|
743 | } else if (to == pl->count) { /* pick it up to the inventory */ |
|
|
744 | /* return if player has already picked it up */ |
|
|
745 | if (op->env == pl) return; |
|
|
746 | |
|
|
747 | pl->contr->count = nrof; |
839 | pl->contr->count = nrof; |
748 | pick_up(pl, op); |
840 | pick_up (pl, op); |
749 | return ; |
841 | return; |
750 | } |
842 | } |
751 | env = esrv_get_ob_from_count(pl, to); |
843 | env = esrv_get_ob_from_count (pl, to); |
752 | if (!env) { |
844 | if (!env) |
753 | LOG(llevDebug, |
845 | { |
754 | "Player '%s' tried to move object to the unknown location (%d)\n", &pl->name, to); |
846 | LOG (llevDebug, "Player '%s' tried to move object to the unknown location (%d)\n", &pl->name, to); |
755 | return; |
847 | return; |
756 | } |
848 | } |
757 | /* put_object_in_sack presumes that necessary sanity checking |
849 | /* put_object_in_sack presumes that necessary sanity checking |
758 | * has already been done (eg, it can be picked up and fits in |
850 | * has already been done (eg, it can be picked up and fits in |
759 | * in a sack, so check for those things. We should also check |
851 | * in a sack, so check for those things. We should also check |
760 | * an make sure env is in fact a container for that matter. |
852 | * an make sure env is in fact a container for that matter. |
761 | */ |
853 | */ |
762 | if (env->type == CONTAINER |
|
|
763 | && can_pick(pl, op) && sack_can_hold(pl, env, op, nrof)) { |
854 | if (env->type == CONTAINER && can_pick (pl, op) && sack_can_hold (pl, env, op, nrof)) |
|
|
855 | { |
764 | put_object_in_sack (pl, env, op, nrof); |
856 | put_object_in_sack (pl, env, op, nrof); |
765 | } |
857 | } |
766 | } |
858 | } |
767 | |
|
|
768 | |
|
|