ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_object.C
(Generate patch)

Comparing deliantra/server/server/c_object.C (file contents):
Revision 1.9 by root, Tue Aug 29 07:34:00 2006 UTC vs.
Revision 1.10 by root, Tue Aug 29 08:01:37 2006 UTC

1/* 1/*
2 * static char *rcsid_c_object_c = 2 * static char *rcsid_c_object_c =
3 * "$Id: c_object.C,v 1.9 2006/08/29 07:34:00 root Exp $"; 3 * "$Id: c_object.C,v 1.10 2006/08/29 08:01:37 root Exp $";
4 */ 4 */
5/* 5/*
6 CrossFire, A Multiplayer game for X-windows 6 CrossFire, A Multiplayer game for X-windows
7 7
8 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 8 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
41 41
42#define OBLINKMALLOC(p) if(!((p)=(objectlink *)malloc(sizeof(objectlink))))\ 42#define OBLINKMALLOC(p) if(!((p)=(objectlink *)malloc(sizeof(objectlink))))\
43 fatal(OUT_OF_MEMORY); 43 fatal(OUT_OF_MEMORY);
44 44
45#define ADD_ITEM(NEW,COUNT)\ 45#define ADD_ITEM(NEW,COUNT)\
46 if(!first) {\ 46 if(!first) {\
47 OBLINKMALLOC(first);\ 47 OBLINKMALLOC(first);\
48 last=first;\ 48 last=first;\
49 } else {\ 49 } else {\
50 OBLINKMALLOC(last->next);\ 50 OBLINKMALLOC(last->next);\
51 last=last->next;\ 51 last=last->next;\
52 }\ 52 }\
53 last->next=NULL;\ 53 last->next=NULL;\
54 last->ob=(NEW);\ 54 last->ob=(NEW);\
55 last->id=(COUNT); 55 last->id=(COUNT);
56 56
57/** 57/**
58 * Search the inventory of 'pl' for what matches best with params. 58 * Search the inventory of 'pl' for what matches best with params.
59 * we use item_matched_string above - this gives us consistent behaviour 59 * we use item_matched_string above - this gives us consistent behaviour
96 96
97int command_rskill ( object *pl, char *params) { 97int command_rskill ( object *pl, char *params) {
98 object *skill; 98 object *skill;
99 99
100 if (!params) { 100 if (!params) {
101 new_draw_info(NDI_UNIQUE, 0, pl, "Usage: ready_skill <skill name>"); 101 new_draw_info(NDI_UNIQUE, 0, pl, "Usage: ready_skill <skill name>");
102 return 0; 102 return 0;
103 } 103 }
104 skill = find_skill_by_name(pl, params); 104 skill = find_skill_by_name(pl, params);
105 105
106 if (!skill) { 106 if (!skill) {
107 new_draw_info_format(NDI_UNIQUE, 0, pl, "You have no knowledge of the skill %s", params); 107 new_draw_info_format(NDI_UNIQUE, 0, pl, "You have no knowledge of the skill %s", params);
108 return 0; 108 return 0;
109 } 109 }
110 return change_skill(pl,skill, 0); 110 return change_skill(pl,skill, 0);
111} 111}
112 112
113 113
132 object *skop; 132 object *skop;
133 133
134 skop = find_skill_by_name(op, skill_names[SK_THROWING]); 134 skop = find_skill_by_name(op, skill_names[SK_THROWING]);
135 if (skop) return do_skill(op, op, skop, op->facing,params); 135 if (skop) return do_skill(op, op, skop, op->facing,params);
136 else { 136 else {
137 new_draw_info(NDI_UNIQUE, 0, op, "You have no knowledge of the skill throwing."); 137 new_draw_info(NDI_UNIQUE, 0, op, "You have no knowledge of the skill throwing.");
138 } 138 }
139 return 0; 139 return 0;
140} 140}
141 141
142 142
150 apply_flag aflag = (apply_flag) 0; 150 apply_flag aflag = (apply_flag) 0;
151 object *inv; 151 object *inv;
152 152
153 while (*params==' ') params++; 153 while (*params==' ') params++;
154 if (!strncmp(params,"-a ",3)) { 154 if (!strncmp(params,"-a ",3)) {
155 aflag=AP_APPLY; 155 aflag=AP_APPLY;
156 params+=3; 156 params+=3;
157 } 157 }
158 if (!strncmp(params,"-u ",3)) { 158 if (!strncmp(params,"-u ",3)) {
159 aflag=AP_UNAPPLY; 159 aflag=AP_UNAPPLY;
160 params+=3; 160 params+=3;
161 } 161 }
162 while (*params==' ') params++; 162 while (*params==' ') params++;
163 163
164 inv=find_best_apply_object_match(op, params, aflag); 164 inv=find_best_apply_object_match(op, params, aflag);
165 if (inv) { 165 if (inv) {
166 player_apply(op,inv,aflag,0); 166 player_apply(op,inv,aflag,0);
167 } else 167 } else
168 new_draw_info_format(NDI_UNIQUE, 0, op, 168 new_draw_info_format(NDI_UNIQUE, 0, op,
169 "Could not find any match to the %s.",params); 169 "Could not find any match to the %s.",params);
170 } 170 }
171 return 0; 171 return 0;
172} 172}
173 173
174/* 174/*
181 * not need to use split_ob and stuff. 181 * not need to use split_ob and stuff.
182 */ 182 */
183int sack_can_hold (object *pl, object *sack, object *op, uint32 nrof) { 183int sack_can_hold (object *pl, object *sack, object *op, uint32 nrof) {
184 184
185 if (! QUERY_FLAG (sack, FLAG_APPLIED)) { 185 if (! QUERY_FLAG (sack, FLAG_APPLIED)) {
186 new_draw_info_format(NDI_UNIQUE, 0, pl, 186 new_draw_info_format(NDI_UNIQUE, 0, pl,
187 "The %s is not active.", query_name(sack)); 187 "The %s is not active.", query_name(sack));
188 return 0; 188 return 0;
189 } 189 }
190 if (sack == op) { 190 if (sack == op) {
191 new_draw_info_format(NDI_UNIQUE, 0, pl, 191 new_draw_info_format(NDI_UNIQUE, 0, pl,
192 "You can't put the %s into itself.", query_name(sack)); 192 "You can't put the %s into itself.", query_name(sack));
193 return 0; 193 return 0;
194 } 194 }
195 if (sack->race && (sack->race != op->race || op->type == CONTAINER 195 if (sack->race && (sack->race != op->race || op->type == CONTAINER
196 || (sack->stats.food && sack->stats.food != op->type))) { 196 || (sack->stats.food && sack->stats.food != op->type))) {
197 new_draw_info_format(NDI_UNIQUE, 0, pl, 197 new_draw_info_format(NDI_UNIQUE, 0, pl,
198 "You can put only %s into the %s.", sack->race, query_name(sack)); 198 "You can put only %s into the %s.", sack->race, query_name(sack));
199 return 0; 199 return 0;
200 } 200 }
201 if (op->type == SPECIAL_KEY && sack->slaying && op->slaying) { 201 if (op->type == SPECIAL_KEY && sack->slaying && op->slaying) {
202 new_draw_info_format(NDI_UNIQUE, 0, pl, 202 new_draw_info_format(NDI_UNIQUE, 0, pl,
203 "You can't put the key into %s.", query_name(sack)); 203 "You can't put the key into %s.", query_name(sack));
204 return 0; 204 return 0;
205 } 205 }
206 if (sack->weight_limit && sack->carrying + (nrof ? nrof : 1) * 206 if (sack->weight_limit && sack->carrying + (nrof ? nrof : 1) *
207 (op->weight + (op->type==CONTAINER?(op->carrying*op->stats.Str):0)) 207 (op->weight + (op->type==CONTAINER?(op->carrying*op->stats.Str):0))
208 * (100 - sack->stats.Str) / 100 > sack->weight_limit) { 208 * (100 - sack->stats.Str) / 100 > sack->weight_limit) {
209 new_draw_info_format(NDI_UNIQUE, 0, pl, 209 new_draw_info_format(NDI_UNIQUE, 0, pl,
210 "That won't fit in the %s!", query_name(sack)); 210 "That won't fit in the %s!", query_name(sack));
211 return 0; 211 return 0;
212 } 212 }
213 /* All other checks pass, must be OK */ 213 /* All other checks pass, must be OK */
214 return 1; 214 return 1;
215} 215}
235 * (sack, luggage, etc), tmp->env->env then points to the player (nested 235 * (sack, luggage, etc), tmp->env->env then points to the player (nested
236 * containers not allowed as of now) 236 * containers not allowed as of now)
237 */ 237 */
238 if((pl->move_type & MOVE_FLYING) && !QUERY_FLAG(pl, FLAG_WIZ) && 238 if((pl->move_type & MOVE_FLYING) && !QUERY_FLAG(pl, FLAG_WIZ) &&
239 is_player_inv(tmp)!=pl) { 239 is_player_inv(tmp)!=pl) {
240 new_draw_info(NDI_UNIQUE, 0,pl, "You are levitating, you can't reach the ground!"); 240 new_draw_info(NDI_UNIQUE, 0,pl, "You are levitating, you can't reach the ground!");
241 return; 241 return;
242 } 242 }
243 if (QUERY_FLAG (tmp, FLAG_NO_DROP)) 243 if (QUERY_FLAG (tmp, FLAG_NO_DROP))
244 return; 244 return;
245 if(QUERY_FLAG(tmp,FLAG_WAS_WIZ) && !QUERY_FLAG(pl, FLAG_WAS_WIZ)) { 245 if(QUERY_FLAG(tmp,FLAG_WAS_WIZ) && !QUERY_FLAG(pl, FLAG_WAS_WIZ)) {
246 new_draw_info(NDI_UNIQUE, 0,pl, "The object disappears in a puff of smoke!"); 246 new_draw_info(NDI_UNIQUE, 0,pl, "The object disappears in a puff of smoke!");
247 new_draw_info(NDI_UNIQUE, 0,pl, "It must have been an illusion."); 247 new_draw_info(NDI_UNIQUE, 0,pl, "It must have been an illusion.");
248 if (pl->type==PLAYER) esrv_del_item (pl->contr, tmp->count); 248 if (pl->type==PLAYER) esrv_del_item (pl->contr, tmp->count);
249 if ( ! QUERY_FLAG (tmp, FLAG_REMOVED)) 249 if ( ! QUERY_FLAG (tmp, FLAG_REMOVED))
250 remove_ob (tmp); 250 remove_ob (tmp);
251 free_object(tmp); 251 free_object(tmp);
252 return; 252 return;
253 } 253 }
254 254
255 if (nrof > tmp_nrof || nrof == 0) 255 if (nrof > tmp_nrof || nrof == 0)
256 nrof = tmp_nrof; 256 nrof = tmp_nrof;
257 /* Figure out how much weight this object will add to the player */ 257 /* Figure out how much weight this object will add to the player */
258 weight = tmp->weight * nrof; 258 weight = tmp->weight * nrof;
259 if (tmp->inv) weight += tmp->carrying * (100 - tmp->stats.Str) / 100; 259 if (tmp->inv) weight += tmp->carrying * (100 - tmp->stats.Str) / 100;
260 if (pl->stats.Str <= MAX_STAT) 260 if (pl->stats.Str <= MAX_STAT)
261 effective_weight_limit = weight_limit[pl->stats.Str]; 261 effective_weight_limit = weight_limit[pl->stats.Str];
262 else 262 else
263 effective_weight_limit = weight_limit[MAX_STAT]; 263 effective_weight_limit = weight_limit[MAX_STAT];
264 if ((pl->weight + pl->carrying + weight) > effective_weight_limit) { 264 if ((pl->weight + pl->carrying + weight) > effective_weight_limit) {
265 new_draw_info(0, 0,pl,"That item is too heavy for you to pick up."); 265 new_draw_info(0, 0,pl,"That item is too heavy for you to pick up.");
266 return; 266 return;
267 } 267 }
268 if (settings.real_wiz == FALSE && QUERY_FLAG(pl, FLAG_WAS_WIZ)) 268 if (settings.real_wiz == FALSE && QUERY_FLAG(pl, FLAG_WAS_WIZ))
269 SET_FLAG(tmp, FLAG_WAS_WIZ); 269 SET_FLAG(tmp, FLAG_WAS_WIZ);
270 if (nrof != tmp_nrof) { 270 if (nrof != tmp_nrof) {
271 object *tmp2 = tmp; 271 object *tmp2 = tmp;
272 tag_t tmp2_tag = tmp2->count; 272 tag_t tmp2_tag = tmp2->count;
273 tmp = get_split_ob (tmp, nrof); 273 tmp = get_split_ob (tmp, nrof);
274 if(!tmp) { 274 if(!tmp) {
275 new_draw_info(NDI_UNIQUE, 0,pl, errmsg); 275 new_draw_info(NDI_UNIQUE, 0,pl, errmsg);
276 return; 276 return;
277 } 277 }
278 /* Tell a client what happened rest of objects */ 278 /* Tell a client what happened rest of objects */
279 if (pl->type == PLAYER) { 279 if (pl->type == PLAYER) {
280 if (was_destroyed (tmp2, tmp2_tag)) 280 if (was_destroyed (tmp2, tmp2_tag))
281 esrv_del_item (pl->contr, tmp2_tag); 281 esrv_del_item (pl->contr, tmp2_tag);
282 else 282 else
283 esrv_send_item (pl, tmp2); 283 esrv_send_item (pl, tmp2);
284 } 284 }
285 } else { 285 } else {
286 /* If the object is in a container, send a delete to the client. 286 /* If the object is in a container, send a delete to the client.
287 * - we are moving all the items from the container to elsewhere, 287 * - we are moving all the items from the container to elsewhere,
288 * so it needs to be deleted. 288 * so it needs to be deleted.
289 */ 289 */
290 if ( ! QUERY_FLAG (tmp, FLAG_REMOVED)) { 290 if ( ! QUERY_FLAG (tmp, FLAG_REMOVED)) {
291 if (tmp->env && pl->type==PLAYER) 291 if (tmp->env && pl->type==PLAYER)
292 esrv_del_item (pl->contr, tmp->count); 292 esrv_del_item (pl->contr, tmp->count);
293 remove_ob(tmp); /* Unlink it */ 293 remove_ob(tmp); /* Unlink it */
294 } 294 }
295 } 295 }
296 if(QUERY_FLAG(tmp, FLAG_UNPAID)) 296 if(QUERY_FLAG(tmp, FLAG_UNPAID))
297 (void) sprintf(buf,"%s will cost you %s.", query_name(tmp), 297 (void) sprintf(buf,"%s will cost you %s.", query_name(tmp),
298 query_cost_string(tmp,pl,F_BUY | F_SHOP)); 298 query_cost_string(tmp,pl,F_BUY | F_SHOP));
299 else 299 else
300 (void) sprintf(buf,"You pick up the %s.", query_name(tmp)); 300 (void) sprintf(buf,"You pick up the %s.", query_name(tmp));
301 new_draw_info(NDI_UNIQUE, 0,pl,buf); 301 new_draw_info(NDI_UNIQUE, 0,pl,buf);
302 302
303 tmp = insert_ob_in_ob(tmp, op); 303 tmp = insert_ob_in_ob(tmp, op);
304 304
305 /* All the stuff below deals with client/server code, and is only 305 /* All the stuff below deals with client/server code, and is only
310 esrv_send_item (pl, tmp); 310 esrv_send_item (pl, tmp);
311 /* These are needed to update the weight for the container we 311 /* These are needed to update the weight for the container we
312 * are putting the object in. 312 * are putting the object in.
313 */ 313 */
314 if (op!=pl) { 314 if (op!=pl) {
315 esrv_update_item (UPD_WEIGHT, pl, op); 315 esrv_update_item (UPD_WEIGHT, pl, op);
316 esrv_send_item (pl, pl); 316 esrv_send_item (pl, pl);
317 } 317 }
318 318
319 /* Update the container the object was in */ 319 /* Update the container the object was in */
320 if (env && env!=pl && env!=op) esrv_update_item (UPD_WEIGHT, pl, env); 320 if (env && env!=pl && env!=op) esrv_update_item (UPD_WEIGHT, pl, env);
321} 321}
334 if (alt) 334 if (alt)
335 { 335 {
336 if ( ! can_pick (op, alt)) { 336 if ( ! can_pick (op, alt)) {
337 new_draw_info_format (NDI_UNIQUE, 0, op, "You can't pick up the %s.", 337 new_draw_info_format (NDI_UNIQUE, 0, op, "You can't pick up the %s.",
338 alt->name); 338 alt->name);
339 goto leave; 339 goto leave;
340 } 340 }
341 tmp = alt; 341 tmp = alt;
342 } 342 }
343 else 343 else
344 { 344 {
358 need_fix_tmp = 1; 358 need_fix_tmp = 1;
359 if ( ! can_pick (op, tmp)) 359 if ( ! can_pick (op, tmp))
360 goto leave; 360 goto leave;
361 361
362 if (op->type==PLAYER) { 362 if (op->type==PLAYER) {
363 count=op->contr->count; 363 count=op->contr->count;
364 if (count==0) count = tmp->nrof; 364 if (count==0) count = tmp->nrof;
365 } 365 }
366 else 366 else
367 count=tmp->nrof; 367 count=tmp->nrof;
368 368
369 /* container is open, so use it */ 369 /* container is open, so use it */
370 if (op->container) { 370 if (op->container) {
371 alt = op->container; 371 alt = op->container;
372 if (alt != tmp->env && !sack_can_hold (op, alt, tmp,count)) 372 if (alt != tmp->env && !sack_can_hold (op, alt, tmp,count))
373 goto leave; 373 goto leave;
374 } else { /* non container pickup */ 374 } else { /* non container pickup */
375 for (alt=op->inv; alt; alt=alt->below)
376 if (alt->type==CONTAINER && QUERY_FLAG(alt, FLAG_APPLIED) &&
377 alt->race && alt->race==tmp->race &&
378 sack_can_hold (NULL, alt, tmp,count))
379 break; /* perfect match */
380
381 if (!alt)
382 for (alt=op->inv; alt; alt=alt->below) 375 for (alt=op->inv; alt; alt=alt->below)
383 if (alt->type==CONTAINER && QUERY_FLAG(alt, FLAG_APPLIED) && 376 if (alt->type==CONTAINER && QUERY_FLAG(alt, FLAG_APPLIED) &&
377 alt->race && alt->race==tmp->race &&
384 sack_can_hold (NULL, alt, tmp,count)) 378 sack_can_hold (NULL, alt, tmp,count))
379 break; /* perfect match */
380
381 if (!alt)
382 for (alt=op->inv; alt; alt=alt->below)
383 if (alt->type==CONTAINER && QUERY_FLAG(alt, FLAG_APPLIED) &&
384 sack_can_hold (NULL, alt, tmp,count))
385 break; /* General container comes next */ 385 break; /* General container comes next */
386 if (!alt) 386 if (!alt)
387 alt = op; /* No free containers */ 387 alt = op; /* No free containers */
388 } 388 }
389 if(tmp->env == alt) { 389 if(tmp->env == alt) {
390 /* here it could be possible to check rent, 390 /* here it could be possible to check rent,
391 * if someone wants to implement it 391 * if someone wants to implement it
392 */ 392 */
393 alt = op; 393 alt = op;
394 } 394 }
395#ifdef PICKUP_DEBUG 395#ifdef PICKUP_DEBUG
396 LOG(llevDebug, "Pick_up(): %s picks %s (%d) and inserts it %s.\n", op->name, tmp->name, op->contr->count, alt->name); 396 LOG(llevDebug, "Pick_up(): %s picks %s (%d) and inserts it %s.\n", op->name, tmp->name, op->contr->count, alt->name);
397#endif 397#endif
398 398
399 /* startequip items are not allowed to be put into containers: */ 399 /* startequip items are not allowed to be put into containers: */
400 if (op->type == PLAYER && alt->type == CONTAINER 400 if (op->type == PLAYER && alt->type == CONTAINER
401 && QUERY_FLAG (tmp, FLAG_STARTEQUIP)) 401 && QUERY_FLAG (tmp, FLAG_STARTEQUIP))
402 { 402 {
403 new_draw_info (NDI_UNIQUE, 0, op, 403 new_draw_info (NDI_UNIQUE, 0, op,
404 "This object cannot be put into containers!"); 404 "This object cannot be put into containers!");
405 goto leave; 405 goto leave;
406 } 406 }
427int command_take (object *op, char *params) 427int command_take (object *op, char *params)
428{ 428{
429 object *tmp, *next; 429 object *tmp, *next;
430 430
431 if (op->container) 431 if (op->container)
432 tmp=op->container->inv; 432 tmp=op->container->inv;
433 else { 433 else {
434 tmp=op->above; 434 tmp=op->above;
435 if (tmp) while (tmp->above) { 435 if (tmp) while (tmp->above) {
436 tmp=tmp->above; 436 tmp=tmp->above;
437 } 437 }
438 if (!tmp) 438 if (!tmp)
439 tmp=op->below; 439 tmp=op->below;
440 } 440 }
441 441
442 if (tmp==NULL) { 442 if (tmp==NULL) {
443 new_draw_info(NDI_UNIQUE, 0,op,"Nothing to take!"); 443 new_draw_info(NDI_UNIQUE, 0,op,"Nothing to take!");
444 return 0; 444 return 0;
445 } 445 }
446 446
447 /* Makes processing easier */ 447 /* Makes processing easier */
448 if (params && *params=='\0') params=NULL; 448 if (params && *params=='\0') params=NULL;
449 449
450 while (tmp) { 450 while (tmp) {
451 next=tmp->below; 451 next=tmp->below;
452 452
453 if (tmp->invisible) { 453 if (tmp->invisible) {
454 tmp=next; 454 tmp=next;
455 continue; 455 continue;
456 } 456 }
457 /* This following two if and else if could be merged into line 457 /* This following two if and else if could be merged into line
458 * but that probably will make it more difficult to read, and 458 * but that probably will make it more difficult to read, and
459 * not make it any more efficient 459 * not make it any more efficient
460 */ 460 */
461 if (params && item_matched_string(op, tmp, params)) { 461 if (params && item_matched_string(op, tmp, params)) {
462 pick_up(op, tmp); 462 pick_up(op, tmp);
463 } 463 }
464 else if (can_pick(op, tmp) && !params) { 464 else if (can_pick(op, tmp) && !params) {
465 pick_up(op,tmp); 465 pick_up(op,tmp);
466 break; 466 break;
467 } 467 }
468 tmp=next; 468 tmp=next;
469 /* Might as well just skip over the player immediately - 469 /* Might as well just skip over the player immediately -
470 * we know it can't be picked up 470 * we know it can't be picked up
471 */ 471 */
472 if (tmp == op) tmp=tmp->below; 472 if (tmp == op) tmp=tmp->below;
473 } 473 }
474 if (!params && !tmp) { 474 if (!params && !tmp) {
475 for (tmp=op->below; tmp!=NULL; tmp=tmp->next) 475 for (tmp=op->below; tmp!=NULL; tmp=tmp->next)
476 if (!tmp->invisible) { 476 if (!tmp->invisible) {
477 char buf[MAX_BUF]; 477 char buf[MAX_BUF];
478 sprintf(buf,"You can't pick up a %s.", 478 sprintf(buf,"You can't pick up a %s.",
479 tmp->name? tmp->name:"null"); 479 tmp->name? tmp->name:"null");
480 new_draw_info(NDI_UNIQUE, 0,op, buf); 480 new_draw_info(NDI_UNIQUE, 0,op, buf);
481 break; 481 break;
482 } 482 }
483 if (!tmp) new_draw_info(NDI_UNIQUE, 0,op, "There is nothing to pick up."); 483 if (!tmp) new_draw_info(NDI_UNIQUE, 0,op, "There is nothing to pick up.");
484 } 484 }
485 return 0; 485 return 0;
486} 486}
487 487
488 488
499 object *tmp2, *sack2; 499 object *tmp2, *sack2;
500 char buf[MAX_BUF]; 500 char buf[MAX_BUF];
501 501
502 if (sack==tmp) return; /* Can't put an object in itself */ 502 if (sack==tmp) return; /* Can't put an object in itself */
503 if (QUERY_FLAG(tmp,FLAG_STARTEQUIP)) { 503 if (QUERY_FLAG(tmp,FLAG_STARTEQUIP)) {
504 new_draw_info_format(NDI_UNIQUE, 0,op, 504 new_draw_info_format(NDI_UNIQUE, 0,op,
505 "You cannot put the %s in the %s.", query_name(tmp), 505 "You cannot put the %s in the %s.", query_name(tmp),
506 query_name(sack)); 506 query_name(sack));
507 return; 507 return;
508 } 508 }
509 if (tmp->type == CONTAINER && tmp->inv) { 509 if (tmp->type == CONTAINER && tmp->inv) {
510 510
511 /* Eneq(@csd.uu.se): If the object to be dropped is a container 511 /* Eneq(@csd.uu.se): If the object to be dropped is a container
512 * we instead move the contents of that container into the active 512 * we instead move the contents of that container into the active
513 * container, this is only done if the object has something in it. 513 * container, this is only done if the object has something in it.
514 */ 514 */
515 sack2 = tmp; 515 sack2 = tmp;
516 new_draw_info_format(NDI_UNIQUE, 0,op, "You move the items from %s into %s.", 516 new_draw_info_format(NDI_UNIQUE, 0,op, "You move the items from %s into %s.",
517 query_name(tmp), query_name(sack)); 517 query_name(tmp), query_name(sack));
518 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp) { 518 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp) {
519 tmp = tmp2->below; 519 tmp = tmp2->below;
520 if ((sack->type == CONTAINER && sack_can_hold(op, op->container, tmp2,tmp2->nrof))) { 520 if ((sack->type == CONTAINER && sack_can_hold(op, op->container, tmp2,tmp2->nrof))) {
521 put_object_in_sack (op, sack, tmp2, 0); 521 put_object_in_sack (op, sack, tmp2, 0);
522 } else { 522 } else {
523 sprintf(buf,"Your %s fills up.", query_name(sack)); 523 sprintf(buf,"Your %s fills up.", query_name(sack));
524 new_draw_info(NDI_UNIQUE, 0,op, buf); 524 new_draw_info(NDI_UNIQUE, 0,op, buf);
525 break; 525 break;
526 } 526 }
527 } 527 }
528 esrv_update_item (UPD_WEIGHT, op, sack2); 528 esrv_update_item (UPD_WEIGHT, op, sack2);
529 return; 529 return;
530 } 530 }
531 531
532 /* Don't worry about this for containers - our caller should have 532 /* Don't worry about this for containers - our caller should have
533 * already checked this. 533 * already checked this.
534 */ 534 */
535 if ((sack->type == CONTAINER) && !sack_can_hold (op, sack, tmp,(nrof?nrof:tmp->nrof))) 535 if ((sack->type == CONTAINER) && !sack_can_hold (op, sack, tmp,(nrof?nrof:tmp->nrof)))
536 return; 536 return;
537 537
538 if(QUERY_FLAG(tmp, FLAG_APPLIED)) { 538 if(QUERY_FLAG(tmp, FLAG_APPLIED)) {
539 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE)) 539 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE))
540 return; 540 return;
541 } 541 }
542 542
543 /* we want to put some portion of the item into the container */ 543 /* we want to put some portion of the item into the container */
544 if (nrof && tmp->nrof != nrof) { 544 if (nrof && tmp->nrof != nrof) {
545 object *tmp2 = tmp; 545 object *tmp2 = tmp;
546 tmp2_tag = tmp2->count; 546 tmp2_tag = tmp2->count;
547 tmp = get_split_ob (tmp, nrof); 547 tmp = get_split_ob (tmp, nrof);
548 548
549 if(!tmp) { 549 if(!tmp) {
550 new_draw_info(NDI_UNIQUE, 0,op, errmsg); 550 new_draw_info(NDI_UNIQUE, 0,op, errmsg);
551 return; 551 return;
552 } 552 }
553 /* Tell a client what happened other objects */ 553 /* Tell a client what happened other objects */
554 if (was_destroyed (tmp2, tmp2_tag)) 554 if (was_destroyed (tmp2, tmp2_tag))
555 esrv_del_item (op->contr, tmp2_tag); 555 esrv_del_item (op->contr, tmp2_tag);
556 else /* this can proably be replaced with an update */ 556 else /* this can proably be replaced with an update */
557 esrv_send_item (op, tmp2); 557 esrv_send_item (op, tmp2);
558 } else 558 } else
559 remove_ob(tmp); 559 remove_ob(tmp);
560 560
561 new_draw_info_format(NDI_UNIQUE, 0,op, "You put the %s in %s.", 561 new_draw_info_format(NDI_UNIQUE, 0,op, "You put the %s in %s.",
562 query_name(tmp), query_name(sack)); 562 query_name(tmp), query_name(sack));
563 tmp_tag = tmp->count; 563 tmp_tag = tmp->count;
564 tmp2 = insert_ob_in_ob(tmp, sack); 564 tmp2 = insert_ob_in_ob(tmp, sack);
565 fix_player(op); /* This is overkill, fix_player() is called somewhere */ 565 fix_player(op); /* This is overkill, fix_player() is called somewhere */
566 /* in object.c */ 566 /* in object.c */
567 567
568 /* If an object merged (and thus, different object), we need to 568 /* If an object merged (and thus, different object), we need to
569 * delete the original. 569 * delete the original.
570 */ 570 */
571 if (tmp2 != tmp) 571 if (tmp2 != tmp)
572 esrv_del_item (op->contr, tmp_tag); 572 esrv_del_item (op->contr, tmp_tag);
573 573
574 esrv_send_item (op, tmp2); 574 esrv_send_item (op, tmp2);
575 575
576 /* update the sacks weight */ 576 /* update the sacks weight */
577 esrv_update_item (UPD_WEIGHT, op, sack); 577 esrv_update_item (UPD_WEIGHT, op, sack);
696 * somehow, players get an invisible object in the container, and the 696 * somehow, players get an invisible object in the container, and the
697 * old logic would skip over invisible objects - works fine for the 697 * old logic would skip over invisible objects - works fine for the
698 * playes inventory, but drop inventory wants to use the next value. 698 * playes inventory, but drop inventory wants to use the next value.
699 */ 699 */
700 if (tmp->invisible) { 700 if (tmp->invisible) {
701 /* if the following is the case, it must be in an container. */ 701 /* if the following is the case, it must be in an container. */
702 if (tmp->env && tmp->env->type != PLAYER) { 702 if (tmp->env && tmp->env->type != PLAYER) {
703 /* Just toss the object - probably shouldn't be hanging 703 /* Just toss the object - probably shouldn't be hanging
704 * around anyways 704 * around anyways
705 */ 705 */
706 remove_ob(tmp); 706 remove_ob(tmp);
707 free_object(tmp); 707 free_object(tmp);
708 return; 708 return;
709 } else { 709 } else {
710 while(tmp!=NULL && tmp->invisible) 710 while(tmp!=NULL && tmp->invisible)
711 tmp=tmp->below; 711 tmp=tmp->below;
712 } 712 }
713 } 713 }
714 714
715 if (tmp==NULL) { 715 if (tmp==NULL) {
716 new_draw_info(NDI_UNIQUE, 0,op,"You don't have anything to drop."); 716 new_draw_info(NDI_UNIQUE, 0,op,"You don't have anything to drop.");
717 return; 717 return;
731 if (op->type == PLAYER) 731 if (op->type == PLAYER)
732 { 732 {
733 if (op->contr->last_used==tmp && op->contr->last_used_id == tmp->count) { 733 if (op->contr->last_used==tmp && op->contr->last_used_id == tmp->count) {
734 object *n=NULL; 734 object *n=NULL;
735 if(tmp->below != NULL) 735 if(tmp->below != NULL)
736 n = tmp->below; 736 n = tmp->below;
737 else if(tmp->above != NULL) 737 else if(tmp->above != NULL)
738 n = tmp->above; 738 n = tmp->above;
739 op->contr->last_used = n; 739 op->contr->last_used = n;
740 if (n != NULL) 740 if (n != NULL)
741 op->contr->last_used_id = n->count; 741 op->contr->last_used_id = n->count;
742 else 742 else
743 op->contr->last_used_id = 0; 743 op->contr->last_used_id = 0;
744 } 744 }
745 }; 745 };
746 746
747 if (op->container) { 747 if (op->container) {
748 if (op->type == PLAYER) 748 if (op->type == PLAYER)
789 789
790 if(params==NULL) { 790 if(params==NULL) {
791 while(curinv != NULL) { 791 while(curinv != NULL) {
792 nextinv = curinv->below; 792 nextinv = curinv->below;
793 while (nextinv && nextinv->type==MONEY) 793 while (nextinv && nextinv->type==MONEY)
794 nextinv = nextinv->below; 794 nextinv = nextinv->below;
795 if(! QUERY_FLAG(curinv,FLAG_INV_LOCKED) && curinv->type != MONEY && 795 if(! QUERY_FLAG(curinv,FLAG_INV_LOCKED) && curinv->type != MONEY &&
796 curinv->type != FOOD && curinv->type != KEY && 796 curinv->type != FOOD && curinv->type != KEY &&
797 curinv->type != SPECIAL_KEY && curinv->type != GEM && 797 curinv->type != SPECIAL_KEY && curinv->type != GEM &&
798 !curinv->invisible && 798 !curinv->invisible &&
799 (curinv->type!=CONTAINER || op->container!=curinv)) 799 (curinv->type!=CONTAINER || op->container!=curinv))
800 { 800 {
801 drop(op,curinv); 801 drop(op,curinv);
802 } 802 }
803 curinv = nextinv; 803 curinv = nextinv;
804 } 804 }
805 } 805 }
806 806
807 else if(strcmp(params, "weapons") == 0) { 807 else if(strcmp(params, "weapons") == 0) {
808 while(curinv != NULL) { 808 while(curinv != NULL) {
809 nextinv = curinv->below; 809 nextinv = curinv->below;
810 while (nextinv && nextinv->type==MONEY) 810 while (nextinv && nextinv->type==MONEY)
811 nextinv = nextinv->below; 811 nextinv = nextinv->below;
812 if(! QUERY_FLAG(curinv,FLAG_INV_LOCKED) && ((curinv->type == WEAPON) || 812 if(! QUERY_FLAG(curinv,FLAG_INV_LOCKED) && ((curinv->type == WEAPON) ||
813 (curinv->type == BOW) || (curinv->type == ARROW))) 813 (curinv->type == BOW) || (curinv->type == ARROW)))
814 { 814 {
815 drop(op,curinv); 815 drop(op,curinv);
816 } 816 }
817 curinv = nextinv; 817 curinv = nextinv;
818 } 818 }
819 } 819 }
820 820
821 else if(strcmp(params, "armor") == 0 || strcmp(params, "armour") == 0) { 821 else if(strcmp(params, "armor") == 0 || strcmp(params, "armour") == 0) {
822 while(curinv != NULL) { 822 while(curinv != NULL) {
823 nextinv = curinv->below; 823 nextinv = curinv->below;
824 while (nextinv && nextinv->type==MONEY) 824 while (nextinv && nextinv->type==MONEY)
825 nextinv = nextinv->below; 825 nextinv = nextinv->below;
826 if(! QUERY_FLAG(curinv,FLAG_INV_LOCKED) && ((curinv->type == ARMOUR) || 826 if(! QUERY_FLAG(curinv,FLAG_INV_LOCKED) && ((curinv->type == ARMOUR) ||
827 curinv->type == SHIELD || curinv->type==HELMET)) 827 curinv->type == SHIELD || curinv->type==HELMET))
828 { 828 {
829 drop(op,curinv); 829 drop(op,curinv);
830 } 830 }
831 curinv = nextinv; 831 curinv = nextinv;
832 } 832 }
833 } 833 }
834 834
835 else if(strcmp(params, "misc") == 0) { 835 else if(strcmp(params, "misc") == 0) {
836 while(curinv != NULL) { 836 while(curinv != NULL) {
837 nextinv = curinv->below; 837 nextinv = curinv->below;
838 while (nextinv && nextinv->type==MONEY) 838 while (nextinv && nextinv->type==MONEY)
839 nextinv = nextinv->below; 839 nextinv = nextinv->below;
840 if(! QUERY_FLAG(curinv,FLAG_INV_LOCKED) && ! QUERY_FLAG(curinv,FLAG_APPLIED)) { 840 if(! QUERY_FLAG(curinv,FLAG_INV_LOCKED) && ! QUERY_FLAG(curinv,FLAG_APPLIED)) {
841 switch(curinv->type) { 841 switch(curinv->type) {
842 case HORN: 842 case HORN:
843 case BOOK: 843 case BOOK:
844 case SPELLBOOK: 844 case SPELLBOOK:
845 case GIRDLE: 845 case GIRDLE:
846 case AMULET: 846 case AMULET:
847 case RING: 847 case RING:
848 case CLOAK: 848 case CLOAK:
849 case BOOTS: 849 case BOOTS:
850 case GLOVES: 850 case GLOVES:
851 case BRACERS: 851 case BRACERS:
852 case SCROLL: 852 case SCROLL:
853 case ARMOUR_IMPROVER: 853 case ARMOUR_IMPROVER:
854 case WEAPON_IMPROVER: 854 case WEAPON_IMPROVER:
855 case WAND: 855 case WAND:
856 case ROD: 856 case ROD:
857 case POTION: 857 case POTION:
858 drop(op,curinv); 858 drop(op,curinv);
859 curinv = nextinv; 859 curinv = nextinv;
860 break; 860 break;
861 default: 861 default:
862 curinv = nextinv; 862 curinv = nextinv;
863 break; 863 break;
864 } 864 }
865 } 865 }
866 curinv = nextinv; 866 curinv = nextinv;
867 } 867 }
868 } 868 }
869 op->contr->socket.update_look=1; 869 op->contr->socket.update_look=1;
879{ 879{
880 object *tmp, *next; 880 object *tmp, *next;
881 int did_one=0; 881 int did_one=0;
882 882
883 if (!params) { 883 if (!params) {
884 new_draw_info(NDI_UNIQUE,0, op, "Drop what?"); 884 new_draw_info(NDI_UNIQUE,0, op, "Drop what?");
885 return 0; 885 return 0;
886 } else { 886 } else {
887 for (tmp=op->inv; tmp; tmp=next) { 887 for (tmp=op->inv; tmp; tmp=next) {
888 next=tmp->below; 888 next=tmp->below;
889 if (QUERY_FLAG(tmp,FLAG_NO_DROP) || 889 if (QUERY_FLAG(tmp,FLAG_NO_DROP) ||
890 tmp->invisible) continue; 890 tmp->invisible) continue;
891 if (item_matched_string(op,tmp,params)) { 891 if (item_matched_string(op,tmp,params)) {
892 drop(op, tmp); 892 drop(op, tmp);
893 did_one=1; 893 did_one=1;
894 } 894 }
895 } 895 }
896 if (!did_one) new_draw_info(NDI_UNIQUE, 0,op,"Nothing to drop."); 896 if (!did_one) new_draw_info(NDI_UNIQUE, 0,op,"Nothing to drop.");
897 } 897 }
898 if (op->type==PLAYER) 898 if (op->type==PLAYER)
899 { 899 {
900 op->contr->count=0; 900 op->contr->count=0;
901 op->contr->socket.update_look=1; 901 op->contr->socket.update_look=1;
914 else { 914 else {
915 object *tmp=find_best_object_match(op,params); 915 object *tmp=find_best_object_match(op,params);
916 if (tmp) 916 if (tmp)
917 examine(op,tmp); 917 examine(op,tmp);
918 else 918 else
919 new_draw_info_format(NDI_UNIQUE,0,op,"Could not find an object that matches %s",params); 919 new_draw_info_format(NDI_UNIQUE,0,op,"Could not find an object that matches %s",params);
920 } 920 }
921 return 0; 921 return 0;
922} 922}
923 923
924/* op should be a player. 924/* op should be a player.
932 object *tmp; 932 object *tmp;
933 933
934 if (!op || !op->contr) return NULL; 934 if (!op || !op->contr) return NULL;
935 if (!op->contr->mark) { 935 if (!op->contr->mark) {
936/* new_draw_info(NDI_UNIQUE,0,op,"You have no marked object");*/ 936/* new_draw_info(NDI_UNIQUE,0,op,"You have no marked object");*/
937 return NULL; 937 return NULL;
938 } 938 }
939 /* This may seem like overkill, but we need to make sure that they 939 /* This may seem like overkill, but we need to make sure that they
940 * player hasn't dropped the item. We use count on the off chance that 940 * player hasn't dropped the item. We use count on the off chance that
941 * an item got reincarnated at some point. 941 * an item got reincarnated at some point.
942 */ 942 */
943 for (tmp=op->inv; tmp; tmp=tmp->below) { 943 for (tmp=op->inv; tmp; tmp=tmp->below) {
944 if (tmp->invisible) continue; 944 if (tmp->invisible) continue;
945 if (tmp == op->contr->mark) { 945 if (tmp == op->contr->mark) {
946 if (tmp->count == op->contr->mark_count) 946 if (tmp->count == op->contr->mark_count)
947 return tmp; 947 return tmp;
948 else { 948 else {
949 op->contr->mark=NULL; 949 op->contr->mark=NULL;
950 op->contr->mark_count=0; 950 op->contr->mark_count=0;
951/* new_draw_info(NDI_UNIQUE,0,op,"You have no marked object");*/ 951/* new_draw_info(NDI_UNIQUE,0,op,"You have no marked object");*/
952 return NULL; 952 return NULL;
953 } 953 }
954 } 954 }
955 } 955 }
956 return NULL; 956 return NULL;
957} 957}
958 958
959 959
963 */ 963 */
964int command_mark(object *op, char *params) 964int command_mark(object *op, char *params)
965{ 965{
966 if (!op->contr) return 1; 966 if (!op->contr) return 1;
967 if (!params) { 967 if (!params) {
968 object *mark=find_marked_object(op); 968 object *mark=find_marked_object(op);
969 if (!mark) new_draw_info(NDI_UNIQUE,0,op,"You have no marked object."); 969 if (!mark) new_draw_info(NDI_UNIQUE,0,op,"You have no marked object.");
970 else new_draw_info_format(NDI_UNIQUE,0,op,"%s is marked.", query_name(mark)); 970 else new_draw_info_format(NDI_UNIQUE,0,op,"%s is marked.", query_name(mark));
971 } 971 }
972 else { 972 else {
973 object *mark1=find_best_object_match(op, params); 973 object *mark1=find_best_object_match(op, params);
974 if (!mark1) { 974 if (!mark1) {
975 new_draw_info_format(NDI_UNIQUE,0,op,"Could not find an object that matches %s",params); 975 new_draw_info_format(NDI_UNIQUE,0,op,"Could not find an object that matches %s",params);
976 return 1; 976 return 1;
977 } 977 }
978 else { 978 else {
979 op->contr->mark=mark1; 979 op->contr->mark=mark1;
980 op->contr->mark_count=mark1->count; 980 op->contr->mark_count=mark1->count;
981 new_draw_info_format(NDI_UNIQUE,0,op,"Marked item %s", query_name(mark1)); 981 new_draw_info_format(NDI_UNIQUE,0,op,"Marked item %s", query_name(mark1));
982 return 0; 982 return 0;
983 } 983 }
984 } 984 }
985 return 0; /*shouldnt get here */ 985 return 0; /*shouldnt get here */
986} 986}
987 987
988 988
991 */ 991 */
992void examine_monster(object *op,object *tmp) { 992void examine_monster(object *op,object *tmp) {
993 object *mon=tmp->head?tmp->head:tmp; 993 object *mon=tmp->head?tmp->head:tmp;
994 994
995 if(QUERY_FLAG(mon,FLAG_UNDEAD)) 995 if(QUERY_FLAG(mon,FLAG_UNDEAD))
996 new_draw_info(NDI_UNIQUE, 0,op,"It is an undead force."); 996 new_draw_info(NDI_UNIQUE, 0,op,"It is an undead force.");
997 if(mon->level>op->level) 997 if(mon->level>op->level)
998 new_draw_info(NDI_UNIQUE, 0,op,"It is likely more powerful than you."); 998 new_draw_info(NDI_UNIQUE, 0,op,"It is likely more powerful than you.");
999 else if(mon->level<op->level) 999 else if(mon->level<op->level)
1000 new_draw_info(NDI_UNIQUE, 0,op,"It is likely less powerful than you."); 1000 new_draw_info(NDI_UNIQUE, 0,op,"It is likely less powerful than you.");
1001 else 1001 else
1002 new_draw_info(NDI_UNIQUE, 0,op,"It is probably as powerful as you."); 1002 new_draw_info(NDI_UNIQUE, 0,op,"It is probably as powerful as you.");
1003 if(mon->attacktype&AT_ACID) 1003 if(mon->attacktype&AT_ACID)
1004 new_draw_info(NDI_UNIQUE, 0,op,"You seem to smell an acrid odor."); 1004 new_draw_info(NDI_UNIQUE, 0,op,"You seem to smell an acrid odor.");
1005 1005
1006 /* Anyone know why this used to use the clone value instead of the 1006 /* Anyone know why this used to use the clone value instead of the
1007 * maxhp field? This seems that it should give more accurate results. 1007 * maxhp field? This seems that it should give more accurate results.
1008 */ 1008 */
1009 switch((mon->stats.hp+1)*4/(mon->stats.maxhp+1)) { /* From 1-4 */ 1009 switch((mon->stats.hp+1)*4/(mon->stats.maxhp+1)) { /* From 1-4 */
1010 case 1: 1010 case 1:
1011 new_draw_info(NDI_UNIQUE, 0,op,"It is in a bad shape."); 1011 new_draw_info(NDI_UNIQUE, 0,op,"It is in a bad shape.");
1012 break; 1012 break;
1013 case 2: 1013 case 2:
1014 new_draw_info(NDI_UNIQUE, 0,op,"It is hurt."); 1014 new_draw_info(NDI_UNIQUE, 0,op,"It is hurt.");
1015 break; 1015 break;
1016 case 3: 1016 case 3:
1017 new_draw_info(NDI_UNIQUE, 0,op,"It is somewhat hurt."); 1017 new_draw_info(NDI_UNIQUE, 0,op,"It is somewhat hurt.");
1018 break; 1018 break;
1019 case 4: 1019 case 4:
1020 new_draw_info(NDI_UNIQUE, 0,op,"It is in excellent shape."); 1020 new_draw_info(NDI_UNIQUE, 0,op,"It is in excellent shape.");
1021 break; 1021 break;
1022 } 1022 }
1023 if(present_in_ob(POISONING,mon)!=NULL) 1023 if(present_in_ob(POISONING,mon)!=NULL)
1024 new_draw_info(NDI_UNIQUE, 0,op,"It looks very ill."); 1024 new_draw_info(NDI_UNIQUE, 0,op,"It looks very ill.");
1025} 1025}
1026 1026
1027 1027
1028/* tmp is the object being described, pl is who is examing it. */ 1028/* tmp is the object being described, pl is who is examing it. */
1029char *long_desc(object *tmp, object *pl) { 1029char *long_desc(object *tmp, object *pl) {
1030 static char buf[VERY_BIG_BUF]; 1030 static char buf[VERY_BIG_BUF];
1031 char *cp; 1031 char *cp;
1032 1032
1033 if(tmp==NULL) 1033 if(tmp==NULL)
1034 return ""; 1034 return "";
1035 1035
1036 buf[0]='\0'; 1036 buf[0]='\0';
1037 switch(tmp->type) { 1037 switch(tmp->type) {
1038 case RING: 1038 case RING:
1039 case SKILL: 1039 case SKILL:
1040 case WEAPON: 1040 case WEAPON:
1041 case ARMOUR: 1041 case ARMOUR:
1042 case BRACERS: 1042 case BRACERS:
1043 case HELMET: 1043 case HELMET:
1044 case SHIELD: 1044 case SHIELD:
1045 case BOOTS: 1045 case BOOTS:
1046 case GLOVES: 1046 case GLOVES:
1047 case AMULET: 1047 case AMULET:
1048 case GIRDLE: 1048 case GIRDLE:
1049 case BOW: 1049 case BOW:
1050 case ARROW: 1050 case ARROW:
1051 case CLOAK: 1051 case CLOAK:
1052 case FOOD: 1052 case FOOD:
1053 case DRINK: 1053 case DRINK:
1054 case FLESH: 1054 case FLESH:
1055 case SKILL_TOOL: 1055 case SKILL_TOOL:
1056 case POWER_CRYSTAL: 1056 case POWER_CRYSTAL:
1057 if(*(cp=describe_item(tmp, pl))!='\0') { 1057 if(*(cp=describe_item(tmp, pl))!='\0') {
1058 int len; 1058 int len;
1059 1059
1060 strncpy(buf,query_name(tmp), VERY_BIG_BUF-1); 1060 strncpy(buf,query_name(tmp), VERY_BIG_BUF-1);
1061 buf[VERY_BIG_BUF-1]=0; 1061 buf[VERY_BIG_BUF-1]=0;
1062 len=strlen(buf); 1062 len=strlen(buf);
1063 if (len<VERY_BIG_BUF-5) { 1063 if (len<VERY_BIG_BUF-5) {
1064 /* Since we know the length, we save a few cpu cycles by using 1064 /* Since we know the length, we save a few cpu cycles by using
1065 * it instead of calling strcat */ 1065 * it instead of calling strcat */
1066 strcpy(buf+len," "); 1066 strcpy(buf+len," ");
1067 len++; 1067 len++;
1068 strncpy(buf+len, cp, VERY_BIG_BUF-len-1); 1068 strncpy(buf+len, cp, VERY_BIG_BUF-len-1);
1069 buf[VERY_BIG_BUF-1]=0; 1069 buf[VERY_BIG_BUF-1]=0;
1070 } 1070 }
1071 } 1071 }
1072 } 1072 }
1073 if(buf[0]=='\0') { 1073 if(buf[0]=='\0') {
1074 strncpy(buf,query_name(tmp), VERY_BIG_BUF-1); 1074 strncpy(buf,query_name(tmp), VERY_BIG_BUF-1);
1075 buf[VERY_BIG_BUF-1]=0; 1075 buf[VERY_BIG_BUF-1]=0;
1076 } 1076 }
1077 1077
1078 return buf; 1078 return buf;
1079} 1079}
1080 1080
1081void examine(object *op, object *tmp) { 1081void examine(object *op, object *tmp) {
1082 char buf[VERY_BIG_BUF]; 1082 char buf[VERY_BIG_BUF];
1083 int i; 1083 int i;
1084 1084
1085 if (tmp == NULL || tmp->type == CLOSE_CON) 1085 if (tmp == NULL || tmp->type == CLOSE_CON)
1086 return; 1086 return;
1087 1087
1088 strcpy(buf,"That is "); 1088 strcpy(buf,"That is ");
1089 strncat(buf, long_desc(tmp, op), VERY_BIG_BUF-strlen(buf)-1); 1089 strncat(buf, long_desc(tmp, op), VERY_BIG_BUF-strlen(buf)-1);
1090 buf[VERY_BIG_BUF-1]=0; 1090 buf[VERY_BIG_BUF-1]=0;
1091 1091
1099 new_draw_info(NDI_UNIQUE, 0,op,buf); 1099 new_draw_info(NDI_UNIQUE, 0,op,buf);
1100 buf[0]='\0'; 1100 buf[0]='\0';
1101 } 1101 }
1102 1102
1103 switch(tmp->type) { 1103 switch(tmp->type) {
1104 case SPELLBOOK: 1104 case SPELLBOOK:
1105 if(QUERY_FLAG(tmp, FLAG_IDENTIFIED) && tmp->inv ) { 1105 if(QUERY_FLAG(tmp, FLAG_IDENTIFIED) && tmp->inv ) {
1106 sprintf(buf,"%s is a %s level %s spell", 1106 sprintf(buf,"%s is a %s level %s spell",
1107 tmp->inv->name, get_levelnumber(tmp->inv->level), 1107 tmp->inv->name, get_levelnumber(tmp->inv->level),
1108 tmp->inv->skill); 1108 tmp->inv->skill);
1109 } 1109 }
1110 break; 1110 break;
1111 1111
1112 case BOOK: 1112 case BOOK:
1113 if(tmp->msg!=NULL) 1113 if(tmp->msg!=NULL)
1114 strcpy(buf,"Something is written in it."); 1114 strcpy(buf,"Something is written in it.");
1115 break; 1115 break;
1116 1116
1117 case CONTAINER: 1117 case CONTAINER:
1118 if(tmp->race!=NULL) { 1118 if(tmp->race!=NULL) {
1119 if(tmp->weight_limit && tmp->stats.Str<100) 1119 if(tmp->weight_limit && tmp->stats.Str<100)
1120 sprintf (buf,"It can hold only %s and its weight limit is %.1f kg.", 1120 sprintf (buf,"It can hold only %s and its weight limit is %.1f kg.",
1121 tmp->race, tmp->weight_limit/(10.0 * (100 - tmp->stats.Str))); 1121 tmp->race, tmp->weight_limit/(10.0 * (100 - tmp->stats.Str)));
1122 else 1122 else
1123 sprintf (buf,"It can hold only %s.", tmp->race); 1123 sprintf (buf,"It can hold only %s.", tmp->race);
1124 } else 1124 } else
1125 if(tmp->weight_limit && tmp->stats.Str<100) 1125 if(tmp->weight_limit && tmp->stats.Str<100)
1126 sprintf (buf,"Its weight limit is %.1f kg.", 1126 sprintf (buf,"Its weight limit is %.1f kg.",
1127 tmp->weight_limit/(10.0 * (100 - tmp->stats.Str))); 1127 tmp->weight_limit/(10.0 * (100 - tmp->stats.Str)));
1128 break; 1128 break;
1129 1129
1130 case WAND: 1130 case WAND:
1131 if(QUERY_FLAG(tmp, FLAG_IDENTIFIED)) 1131 if(QUERY_FLAG(tmp, FLAG_IDENTIFIED))
1132 sprintf(buf,"It has %d charges left.",tmp->stats.food); 1132 sprintf(buf,"It has %d charges left.",tmp->stats.food);
1133 break; 1133 break;
1134 } 1134 }
1135 1135
1136 if(buf[0]!='\0') 1136 if(buf[0]!='\0')
1137 new_draw_info(NDI_UNIQUE, 0,op,buf); 1137 new_draw_info(NDI_UNIQUE, 0,op,buf);
1138 1138
1139 if(tmp->materialname != NULL && !tmp->msg) { 1139 if(tmp->materialname != NULL && !tmp->msg) {
1140 sprintf(buf, "It is made of: %s.", tmp->materialname); 1140 sprintf(buf, "It is made of: %s.", tmp->materialname);
1141 new_draw_info(NDI_UNIQUE, 0, op, buf); 1141 new_draw_info(NDI_UNIQUE, 0, op, buf);
1142 } 1142 }
1143 /* Where to wear this item */ 1143 /* Where to wear this item */
1144 for (i=0; i < NUM_BODY_LOCATIONS; i++) { 1144 for (i=0; i < NUM_BODY_LOCATIONS; i++) {
1145 if (tmp->body_info[i]<-1) { 1145 if (tmp->body_info[i]<-1) {
1146 if (op->body_info[i]) 1146 if (op->body_info[i])
1147 new_draw_info_format(NDI_UNIQUE, 0,op, 1147 new_draw_info_format(NDI_UNIQUE, 0,op,
1148 "It goes %s (%d)", body_locations[i].use_name, -tmp->body_info[i]); 1148 "It goes %s (%d)", body_locations[i].use_name, -tmp->body_info[i]);
1149 else 1149 else
1150 new_draw_info_format(NDI_UNIQUE, 0,op, 1150 new_draw_info_format(NDI_UNIQUE, 0,op,
1151 "It goes %s", body_locations[i].nonuse_name); 1151 "It goes %s", body_locations[i].nonuse_name);
1152 } else if (tmp->body_info[i]) { 1152 } else if (tmp->body_info[i]) {
1153 if (op->body_info[i]) 1153 if (op->body_info[i])
1154 new_draw_info_format(NDI_UNIQUE, 0,op, 1154 new_draw_info_format(NDI_UNIQUE, 0,op,
1155 "It goes %s", body_locations[i].use_name); 1155 "It goes %s", body_locations[i].use_name);
1156 else 1156 else
1157 new_draw_info_format(NDI_UNIQUE, 0,op, 1157 new_draw_info_format(NDI_UNIQUE, 0,op,
1158 "It goes %s", body_locations[i].nonuse_name); 1158 "It goes %s", body_locations[i].nonuse_name);
1159 } 1159 }
1160 } 1160 }
1161 1161
1162 if(tmp->weight) { 1162 if(tmp->weight) {
1163 sprintf(buf,tmp->nrof>1?"They weigh %3.3f kg.":"It weighs %3.3f kg.", 1163 sprintf(buf,tmp->nrof>1?"They weigh %3.3f kg.":"It weighs %3.3f kg.",
1164 tmp->weight*(tmp->nrof?tmp->nrof:1)/1000.0); 1164 tmp->weight*(tmp->nrof?tmp->nrof:1)/1000.0);
1165 new_draw_info(NDI_UNIQUE, 0,op,buf); 1165 new_draw_info(NDI_UNIQUE, 0,op,buf);
1166 } 1166 }
1167 1167
1168 if (tmp->value && !QUERY_FLAG(tmp, FLAG_STARTEQUIP) && !QUERY_FLAG(tmp, FLAG_NO_PICK)) { 1168 if (tmp->value && !QUERY_FLAG(tmp, FLAG_STARTEQUIP) && !QUERY_FLAG(tmp, FLAG_NO_PICK)) {
1169 object *floor; 1169 object *floor;
1170 sprintf(buf,"You reckon %s worth %s.", 1170 sprintf(buf,"You reckon %s worth %s.",
1171 tmp->nrof>1?"they are":"it is",query_cost_string(tmp,op, F_TRUE | F_APPROX)); 1171 tmp->nrof>1?"they are":"it is",query_cost_string(tmp,op, F_TRUE | F_APPROX));
1172 new_draw_info(NDI_UNIQUE, 0,op,buf);
1173 floor = get_map_ob (op->map, op->x, op->y);
1174 if (floor && floor->type == SHOP_FLOOR) {
1175 if(QUERY_FLAG(tmp, FLAG_UNPAID))
1176 sprintf(buf,"%s would cost you %s.",
1177 tmp->nrof>1?"They":"It",query_cost_string(tmp,op,F_BUY | F_SHOP));
1178 else
1179 sprintf(buf,"You are offered %s for %s.",
1180 query_cost_string(tmp,op,F_SELL+F_SHOP), tmp->nrof>1?"them":"it");
1181 new_draw_info(NDI_UNIQUE, 0,op,buf); 1172 new_draw_info(NDI_UNIQUE, 0,op,buf);
1182 } 1173 floor = get_map_ob (op->map, op->x, op->y);
1174 if (floor && floor->type == SHOP_FLOOR) {
1175 if(QUERY_FLAG(tmp, FLAG_UNPAID))
1176 sprintf(buf,"%s would cost you %s.",
1177 tmp->nrof>1?"They":"It",query_cost_string(tmp,op,F_BUY | F_SHOP));
1178 else
1179 sprintf(buf,"You are offered %s for %s.",
1180 query_cost_string(tmp,op,F_SELL+F_SHOP), tmp->nrof>1?"them":"it");
1181 new_draw_info(NDI_UNIQUE, 0,op,buf);
1182 }
1183 } 1183 }
1184 1184
1185 if(QUERY_FLAG(tmp, FLAG_MONSTER)) 1185 if(QUERY_FLAG(tmp, FLAG_MONSTER))
1186 examine_monster(op,tmp); 1186 examine_monster(op,tmp);
1187 1187
1188 /* Is this item buildable? */ 1188 /* Is this item buildable? */
1189 if ( QUERY_FLAG( tmp, FLAG_IS_BUILDABLE ) ) 1189 if ( QUERY_FLAG( tmp, FLAG_IS_BUILDABLE ) )
1190 new_draw_info( NDI_UNIQUE, 0, op, "This is a buildable item." ); 1190 new_draw_info( NDI_UNIQUE, 0, op, "This is a buildable item." );
1191 1191
1194 */ 1194 */
1195 if(tmp->msg && tmp->type != EXIT && tmp->type != BOOK && 1195 if(tmp->msg && tmp->type != EXIT && tmp->type != BOOK &&
1196 tmp->type != CORPSE && !tmp->move_on && 1196 tmp->type != CORPSE && !tmp->move_on &&
1197 strncasecmp(tmp->msg, "@match",7)) { 1197 strncasecmp(tmp->msg, "@match",7)) {
1198 1198
1199 /* This is just a hack so when identifying the items, we print 1199 /* This is just a hack so when identifying the items, we print
1200 * out the extra message 1200 * out the extra message
1201 */ 1201 */
1202 if (need_identify(tmp) && QUERY_FLAG(tmp, FLAG_IDENTIFIED)) 1202 if (need_identify(tmp) && QUERY_FLAG(tmp, FLAG_IDENTIFIED))
1203 new_draw_info(NDI_UNIQUE, 0,op, "The object has a story:"); 1203 new_draw_info(NDI_UNIQUE, 0,op, "The object has a story:");
1204 1204
1205 new_draw_info(NDI_UNIQUE, 0,op,tmp->msg); 1205 new_draw_info(NDI_UNIQUE, 0,op,tmp->msg);
1206 } 1206 }
1207 new_draw_info(NDI_UNIQUE, 0,op," "); /* Blank line */ 1207 new_draw_info(NDI_UNIQUE, 0,op," "); /* Blank line */
1208} 1208}
1209 1209
1210/* 1210/*
1253 if((!op||!QUERY_FLAG(op, FLAG_WIZ)) && (tmp->invisible || 1253 if((!op||!QUERY_FLAG(op, FLAG_WIZ)) && (tmp->invisible ||
1254 (inv && inv->type != CONTAINER && !QUERY_FLAG(tmp, FLAG_APPLIED)))) 1254 (inv && inv->type != CONTAINER && !QUERY_FLAG(tmp, FLAG_APPLIED))))
1255 continue; 1255 continue;
1256 if((!op || QUERY_FLAG(op, FLAG_WIZ))) 1256 if((!op || QUERY_FLAG(op, FLAG_WIZ)))
1257 new_draw_info_format(NDI_UNIQUE, 0,op ,"%s- %-*.*s (%5d) %-8s", in, length, length, 1257 new_draw_info_format(NDI_UNIQUE, 0,op ,"%s- %-*.*s (%5d) %-8s", in, length, length,
1258 query_name(tmp), tmp->count,query_weight(tmp)); 1258 query_name(tmp), tmp->count,query_weight(tmp));
1259 else 1259 else
1260 new_draw_info_format(NDI_UNIQUE,0, op, "%s- %-*.*s %-8s", in, length+8, 1260 new_draw_info_format(NDI_UNIQUE,0, op, "%s- %-*.*s %-8s", in, length+8,
1261 length+8, query_name(tmp), 1261 length+8, query_name(tmp),
1262 query_weight(tmp)); 1262 query_weight(tmp));
1263 } 1263 }
1264 if(!inv && op) { 1264 if(!inv && op) {
1265 new_draw_info_format(NDI_UNIQUE,0, op ,"%-*s %-8s", 1265 new_draw_info_format(NDI_UNIQUE,0, op ,"%-*s %-8s",
1266 41,"Total weight :",query_weight(op)); 1266 41,"Total weight :",query_weight(op));
1405int command_search_items (object *op, char *params) 1405int command_search_items (object *op, char *params)
1406{ 1406{
1407 char buf[MAX_BUF]; 1407 char buf[MAX_BUF];
1408 1408
1409 if (settings.search_items == FALSE) 1409 if (settings.search_items == FALSE)
1410 return 1; 1410 return 1;
1411 1411
1412 if(params == NULL) { 1412 if(params == NULL) {
1413 if(op->contr->search_str[0]=='\0') { 1413 if(op->contr->search_str[0]=='\0') {
1414 new_draw_info(NDI_UNIQUE, 0,op,"Example: search magic+1"); 1414 new_draw_info(NDI_UNIQUE, 0,op,"Example: search magic+1");
1415 new_draw_info(NDI_UNIQUE, 0,op,"Would automatically pick up all"); 1415 new_draw_info(NDI_UNIQUE, 0,op,"Would automatically pick up all");
1416 new_draw_info(NDI_UNIQUE, 0,op,"items containing the word 'magic+1'."); 1416 new_draw_info(NDI_UNIQUE, 0,op,"items containing the word 'magic+1'.");
1417 return 1; 1417 return 1;
1418 } 1418 }
1419 op->contr->search_str[0]='\0'; 1419 op->contr->search_str[0]='\0';
1420 new_draw_info(NDI_UNIQUE, 0,op,"Search mode turned off."); 1420 new_draw_info(NDI_UNIQUE, 0,op,"Search mode turned off.");
1421 fix_player(op); 1421 fix_player(op);
1422 return 1; 1422 return 1;
1423 } 1423 }
1424 if((int)strlen(params) >= MAX_BUF) { 1424 if((int)strlen(params) >= MAX_BUF) {
1425 new_draw_info(NDI_UNIQUE, 0,op,"Search string too long."); 1425 new_draw_info(NDI_UNIQUE, 0,op,"Search string too long.");
1426 return 1; 1426 return 1;
1427 } 1427 }
1428 strcpy(op->contr->search_str, params); 1428 strcpy(op->contr->search_str, params);
1429 sprintf(buf,"Searching for '%s'.",op->contr->search_str); 1429 sprintf(buf,"Searching for '%s'.",op->contr->search_str);
1430 new_draw_info(NDI_UNIQUE, 0,op,buf); 1430 new_draw_info(NDI_UNIQUE, 0,op,buf);
1431 fix_player(op); 1431 fix_player(op);
1454 /* Let's skip white spaces */ 1454 /* Let's skip white spaces */
1455 while(' '==*params) params++; 1455 while(' '==*params) params++;
1456 1456
1457 /* Checking the first part */ 1457 /* Checking the first part */
1458 if ((itemnumber = atoi(params))!=0) { 1458 if ((itemnumber = atoi(params))!=0) {
1459 for (item=op->inv; item && ((item->count != itemnumber) || item->invisible); item=item->below); 1459 for (item=op->inv; item && ((item->count != itemnumber) || item->invisible); item=item->below);
1460 if (!item) { 1460 if (!item) {
1461 new_draw_info(NDI_UNIQUE,0,op,"Tried to rename an invalid item."); 1461 new_draw_info(NDI_UNIQUE,0,op,"Tried to rename an invalid item.");
1462 return 1; 1462 return 1;
1463 } 1463 }
1464 while(isdigit(*params) || ' '==*params) params++; 1464 while(isdigit(*params) || ' '==*params) params++;
1465 } 1465 }
1466 else if ('<'==*params) { 1466 else if ('<'==*params) {
1467 /* Got old name, let's get it & find appropriate matching item */ 1467 /* Got old name, let's get it & find appropriate matching item */
1468 closebrace=strchr(params,'>'); 1468 closebrace=strchr(params,'>');
1469 if(!closebrace) { 1469 if(!closebrace) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines