version 1.12 | | version 1.13 |
---|
| | |
/* | | /* |
* static char *rcsid_c_object_c = | | * static char *rcsid_c_object_c = |
* "$Id: c_object.c,v 1.12 2000/11/03 05:42:56 cvs Exp $"; | | * "$Id: c_object.c,v 1.13 2000/11/06 23:06:47 jec Exp $"; |
*/ | | */ |
/* | | /* |
CrossFire, A Multiplayer game for X-windows | | CrossFire, A Multiplayer game for X-windows |
| | |
* tmp is the object to pick up, nrof is the number to | | * tmp is the object to pick up, nrof is the number to |
* pick up (0 means all of them) | | * pick up (0 means all of them) |
*/ | | */ |
void pick_up_object (object *pl, object *op, object *tmp, int nrof) | | static void pick_up_object (object *pl, object *op, object *tmp, int nrof) |
{ | | { |
/* buf needs to be big (more than 256 chars) because you can get | | /* buf needs to be big (more than 256 chars) because you can get |
* very long item names. | | * very long item names. |
*/ | | */ |
char buf[HUGE_BUF]; | | char buf[HUGE_BUF]; |
object *env=tmp->env; | | object *env=tmp->env; |
uint32 weight; | | uint32 weight, effective_weight_limit; |
| | int tmp_nrof = tmp->nrof ? tmp->nrof : 1; |
| | |
/* IF the player is flying & trying to take the item out of a container | | /* IF the player is flying & trying to take the item out of a container |
* that is in his inventory, let him. tmp->env points to the container | | * that is in his inventory, let him. tmp->env points to the container |
| | |
new_draw_info(NDI_UNIQUE, 0,pl, "You are levitating, you can't reach the ground!"); | | new_draw_info(NDI_UNIQUE, 0,pl, "You are levitating, you can't reach the ground!"); |
return; | | return; |
} | | } |
if(!can_pick(pl,tmp)) { | | |
if (tmp->name!=NULL) { | | |
sprintf(buf,"You can't pick up a %s", tmp->name); | | |
new_draw_info(NDI_UNIQUE, 0,pl, buf); | | |
} | | |
else | | |
new_draw_info(NDI_UNIQUE, 0,pl,"You can't take that!"); | | |
return; | | |
} | | |
if (QUERY_FLAG (tmp, FLAG_NO_DROP)) | | if (QUERY_FLAG (tmp, FLAG_NO_DROP)) |
return; | | return; |
if(QUERY_FLAG(tmp,FLAG_WAS_WIZ) && !QUERY_FLAG(pl, FLAG_WAS_WIZ)) { | | if(QUERY_FLAG(tmp,FLAG_WAS_WIZ) && !QUERY_FLAG(pl, FLAG_WAS_WIZ)) { |
new_draw_info(NDI_UNIQUE, 0,pl, "The object disappears in a puff of smoke!"); | | new_draw_info(NDI_UNIQUE, 0,pl, "The object disappears in a puff of smoke!"); |
new_draw_info(NDI_UNIQUE, 0,pl, "It must have been an illusion."); | | new_draw_info(NDI_UNIQUE, 0,pl, "It must have been an illusion."); |
if (pl->type==PLAYER) esrv_del_item (pl->contr, tmp->count); | | if (pl->type==PLAYER) esrv_del_item (pl->contr, tmp->count); |
| | if ( ! QUERY_FLAG (tmp, FLAG_REMOVED)) |
remove_ob(tmp); | | remove_ob(tmp); |
free_object(tmp); | | free_object(tmp); |
return; | | return; |
} | | } |
| | |
/* startequip items are not allowed to be put into containers: */ | | if (nrof > tmp_nrof || nrof == 0) |
if (pl->type == PLAYER && op->type == CONTAINER && | | nrof = tmp_nrof; |
QUERY_FLAG(tmp, FLAG_STARTEQUIP)) { | | |
new_draw_info(NDI_UNIQUE, 0,pl,"This object cannot be put into containers!"); | | |
return; | | |
} | | |
| | |
if (nrof==0 || nrof>tmp->nrof) nrof=(tmp->nrof?tmp->nrof:1); | | |
/* Figure out how much weight this object will add to the player */ | | /* Figure out how much weight this object will add to the player */ |
weight = tmp->weight * nrof; | | weight = tmp->weight * nrof; |
if (tmp->inv) weight += tmp->carrying * (100 - tmp->stats.Str) / 100; | | if (tmp->inv) weight += tmp->carrying * (100 - tmp->stats.Str) / 100; |
if ((pl->weight + pl->carrying +weight) > weight_limit[pl->stats.Str]) { | | if (pl->stats.Str <= MAX_STAT) |
| | effective_weight_limit = weight_limit[pl->stats.Str]; |
| | else |
| | effective_weight_limit = weight_limit[MAX_STAT]; |
| | if ((pl->weight + pl->carrying + weight) > effective_weight_limit) { |
new_draw_info(NDI_UNIQUE, 0,pl,"That item is too heavy for you to pick up."); | | new_draw_info(NDI_UNIQUE, 0,pl,"That item is too heavy for you to pick up."); |
return; | | return; |
} | | } |
| | |
SET_FLAG(tmp, FLAG_WAS_WIZ); | | SET_FLAG(tmp, FLAG_WAS_WIZ); |
#endif | | #endif |
| | |
if(nrof != tmp->nrof && !(nrof == 1 && tmp->nrof == 0)) { | | if (nrof != tmp_nrof) { |
object *tmp2 = tmp; | | object *tmp2 = tmp; |
tag_t tmp2_tag = tmp2->count; | | tag_t tmp2_tag = tmp2->count; |
tmp = get_split_ob (tmp, nrof); | | tmp = get_split_ob (tmp, nrof); |
| | |
* - we are moving all the items from the container to elsewhere, | | * - we are moving all the items from the container to elsewhere, |
* so it needs to be deleted. | | * so it needs to be deleted. |
*/ | | */ |
| | if ( ! QUERY_FLAG (tmp, FLAG_REMOVED)) { |
if (tmp->env && pl->type==PLAYER) | | if (tmp->env && pl->type==PLAYER) |
esrv_del_item (pl->contr, tmp->count); | | esrv_del_item (pl->contr, tmp->count); |
remove_ob(tmp); /* Unlink it */ | | remove_ob(tmp); /* Unlink it */ |
} | | } |
| | } |
if(QUERY_FLAG(tmp, FLAG_UNPAID)) | | if(QUERY_FLAG(tmp, FLAG_UNPAID)) |
(void) sprintf(buf,"%s will cost you %s.", query_name(tmp), | | (void) sprintf(buf,"%s will cost you %s.", query_name(tmp), |
query_cost_string(tmp,op,F_BUY)); | | query_cost_string(tmp,op,F_BUY)); |
| | |
void pick_up(object *op,object *alt) | | void pick_up(object *op,object *alt) |
/* modified slightly to allow monsters use this -b.t. 5-31-95 */ | | /* modified slightly to allow monsters use this -b.t. 5-31-95 */ |
{ | | { |
object *tmp=NULL; | | int need_fix_tmp = 0; |
| | object *tmp; |
| | mapstruct *tmp_map; |
int count; | | int count; |
| | tag_t tag; |
| | |
| | /* Decide which object to pick. */ |
if(alt) | | if(alt) |
| | { |
| | if ( ! can_pick (op, alt)) { |
| | new_draw_info_format (NDI_UNIQUE, 0, op, "You can't pick up a %s.", |
| | alt->name); |
| | goto leave; |
| | } |
tmp=alt; | | tmp=alt; |
else if(op->below==NULL || !can_pick(op, tmp)) { | | } |
new_draw_info(NDI_UNIQUE, 0,op,"There is nothing to pick up here."); | | else |
return; | | { |
} else | | if (op->below == NULL || ! can_pick (op, op->below)) { |
| | new_draw_info (NDI_UNIQUE, 0, op, |
| | "There is nothing to pick up here."); |
| | goto leave; |
| | } |
tmp=op->below; | | tmp=op->below; |
| | } |
| | |
if (op->type==PLAYER && op->contr->count && op->contr->count <tmp->nrof) | | /* Try to catch it. */ |
| | tmp_map = tmp->map; |
| | tmp = stop_item (tmp); |
| | if (tmp == NULL) |
| | goto leave; |
| | need_fix_tmp = 1; |
| | if ( ! can_pick (op, tmp)) |
| | goto leave; |
| | |
| | if (op->type==PLAYER) |
count=op->contr->count; | | count=op->contr->count; |
else | | else |
count=tmp->nrof; | | count=tmp->nrof; |
| | |
if (op->container) { | | if (op->container) { |
alt = op->container; | | alt = op->container; |
if (alt != tmp->env && !sack_can_hold (op, alt, tmp,count)) | | if (alt != tmp->env && !sack_can_hold (op, alt, tmp,count)) |
return; | | goto leave; |
} else { /* non container pickup */ | | } else { /* non container pickup */ |
for (alt=op->inv; alt; alt=alt->below) | | for (alt=op->inv; alt; alt=alt->below) |
if (alt->type==CONTAINER && QUERY_FLAG(alt, FLAG_APPLIED) && | | if (alt->type==CONTAINER && QUERY_FLAG(alt, FLAG_APPLIED) && |
| | |
#ifdef PICKUP_DEBUG | | #ifdef PICKUP_DEBUG |
printf ("Pick_up(): %s picks %s (%d) and inserts it %s.\n",op->name, tmp->name, op->contr->count, alt->name); | | printf ("Pick_up(): %s picks %s (%d) and inserts it %s.\n",op->name, tmp->name, op->contr->count, alt->name); |
#endif | | #endif |
if(op->type==PLAYER) { | | |
pick_up_object(op, alt, tmp, op->contr->count); | | /* startequip items are not allowed to be put into containers: */ |
| | if (op->type == PLAYER && alt->type == CONTAINER |
| | && QUERY_FLAG (tmp, FLAG_STARTEQUIP)) |
| | { |
| | new_draw_info (NDI_UNIQUE, 0, op, |
| | "This object cannot be put into containers!"); |
| | goto leave; |
| | } |
| | |
| | tag = tmp->count; |
| | pick_up_object (op, alt, tmp, count); |
| | if (was_destroyed (tmp, tag) || tmp->env) |
| | need_fix_tmp = 0; |
| | if (op->type == PLAYER) |
op->contr->count=0; | | op->contr->count=0; |
} else | | goto leave; |
pick_up_object(op, alt, tmp, tmp->nrof); | | |
| | leave: |
| | if (need_fix_tmp) |
| | fix_stopped_item (tmp, tmp_map, op); |
} | | } |
| | |
| | |
| | |
for (tmp=op->below; tmp!=NULL; tmp=tmp->next) | | for (tmp=op->below; tmp!=NULL; tmp=tmp->next) |
if (!tmp->invisible) { | | if (!tmp->invisible) { |
char buf[MAX_BUF]; | | char buf[MAX_BUF]; |
sprintf(buf,"You can't pick up a %s", | | sprintf(buf,"You can't pick up a %s.", |
tmp->name? tmp->name:"null"); | | tmp->name? tmp->name:"null"); |
new_draw_info(NDI_UNIQUE, 0,op, buf); | | new_draw_info(NDI_UNIQUE, 0,op, buf); |
break; | | break; |