Crossfire Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
CF: Re: apply() cleanup
- To: crossfire (at) ifi.uio.no
- Subject: CF: Re: apply() cleanup
- From: Jan Echternach <>
- Date: Thu, 20 Apr 2000 04:51:37 +0200
- In-Reply-To: <>; from on Thu, Apr 20, 2000 at 04:48:20AM +0200
- Mail-Followup-To:
- References: <>
- Reply-To: Jan Echternach <>
- Sender:
On Thu, Apr 20, 2000 at 04:48:20AM +0200, Jan Echternach wrote:
> The attached patch
Umm...
--
Jan
diff -rc orig/crossfire-0.95.5-patch12/include/sproto.h crossfire-0.95.5/include/sproto.h
*** orig/crossfire-0.95.5-patch12/include/sproto.h Thu Apr 20 04:10:36 2000
--- crossfire-0.95.5/include/sproto.h Thu Apr 20 03:21:32 2000
***************
*** 36,42 ****
extern char *gravestone_text ( object *op );
extern int make_gravestone ( object *op, object *grave );
extern int apply ( object *op, object *tmp, int aflag );
! extern void apply_below ( object *op );
extern int apply_special ( object *who, object *op, int aflags );
extern int auto_apply ( object *op );
extern void fix_auto_apply ( mapstruct *m );
--- 36,43 ----
extern char *gravestone_text ( object *op );
extern int make_gravestone ( object *op, object *grave );
extern int apply ( object *op, object *tmp, int aflag );
! extern int player_apply ( object *pl, object *op, int aflag, int quiet );
! extern void player_apply_below ( object *pl );
extern int apply_special ( object *who, object *op, int aflags );
extern int auto_apply ( object *op );
extern void fix_auto_apply ( mapstruct *m );
***************
*** 120,126 ****
extern object *find_best_object_match ( object *pl, char *params );
extern int command_uskill ( object *pl, char *params );
extern int command_rskill ( object *pl, char *params );
- extern void apply_inventory ( object *op );
extern int command_apply ( object *op, char *params );
extern int sack_can_hold ( object *pl, object *sack, object *op, int nrof );
extern void pick_up_object ( object *pl, object *op, object *tmp, int nrof );
--- 121,126 ----
diff -rc orig/crossfire-0.95.5-patch12/server/apply.c crossfire-0.95.5/server/apply.c
*** orig/crossfire-0.95.5-patch12/server/apply.c Thu Apr 13 01:06:17 2000
--- crossfire-0.95.5/server/apply.c Thu Apr 20 04:01:39 2000
***************
*** 1038,1045 ****
* object.
*
* crossfire-0.95.5: Return value of apply() is currently used by
! * apply_below() in apply.c, apply_inventory() in c_object.c and
! * check_good_weapon()/check_good_armour() in monster.c
*
*/
/* op is the object that is causing object to be applied, tmp is the object
--- 1038,1054 ----
* object.
*
* crossfire-0.95.5: Return value of apply() is currently used by
! * player_apply() in apply.c and check_good_weapon()/check_good_armour()
! * in monster.c.
! *
! * FIXME: player_apply() uses the return value as "Was this a useable
! * item, or should we continue searching for useable items?", whereas
! * check_good_weapon() uses it as "Have we successfully applied the object?".
! * There is a difference between these two interpretations for objects that
! * could be applied sometimes but can't be applied right now. For example,
! * players can get a "marked item is not armour" message, followed by a
! * "don't know how to apply Enchant Armour" message, because the
! * improve armour code uses the second interpretation.
*
*/
/* op is the object that is causing object to be applied, tmp is the object
***************
*** 1050,1086 ****
int apply(object *op, object *tmp, int aflag) {
char buf[MAX_BUF];
- int inven;
! if(tmp==NULL) {
! if(op!=NULL&&op->type==PLAYER)
! new_draw_info(NDI_UNIQUE, 0,op,"There is nothing to apply.");
! return 0;
! }
! inven=(tmp->env!=NULL);
! if(op->type==PLAYER&&!inven&&QUERY_FLAG(op,FLAG_FLYING)&&
! !QUERY_FLAG(tmp,FLAG_FLYING)&&!QUERY_FLAG(tmp,FLAG_FLY_ON)&&
! !QUERY_FLAG(op,FLAG_WIZ)) {
! new_draw_info(NDI_UNIQUE, 0,op,"But you are floating high above the ground!");
! return 0;
! }
! while(tmp!=NULL&&(!(QUERY_FLAG(tmp,FLAG_WALK_ON)||QUERY_FLAG(tmp,FLAG_FLY_ON))
! &&tmp->invisible))
! tmp=inven?tmp->below:tmp->above;
! if(tmp==NULL)
return 0;
- if(QUERY_FLAG(tmp,FLAG_WAS_WIZ)&&!QUERY_FLAG(op,FLAG_WAS_WIZ)&&op->type==PLAYER) {
- play_sound_map(op->map, op->x, op->y, SOUND_OB_EVAPORATE);
- new_draw_info(NDI_UNIQUE, 0,op,"The object disappears in a puff of smoke!");
- new_draw_info(NDI_UNIQUE, 0,op,"It must have been an illusion.");
- remove_ob(tmp);
- free_object(tmp);
- return 1;
- }
- if(op->type==PLAYER) {
- op->contr->last_used=tmp;
- op->contr->last_used_id=tmp->count;
}
switch(tmp->type) {
case PLAYERMOVER:
if (tmp->attacktype && (tmp->level || op->type!=PLAYER)) {
--- 1059,1071 ----
int apply(object *op, object *tmp, int aflag) {
char buf[MAX_BUF];
! if (tmp==NULL) {
! LOG (llevError, "BUG: apply(): arch %s, name %s tried to apply a "
! "null pointer\n", op->arch->name, tmp->name);
return 0;
}
+
switch(tmp->type) {
case PLAYERMOVER:
if (tmp->attacktype && (tmp->level || op->type!=PLAYER)) {
***************
*** 1886,1915 ****
case IDENTIFY_ALTAR:
return apply_id_altar(op, tmp);
default:
- #if 0
- if(op->type==PLAYER) {
- new_draw_info(NDI_UNIQUE, 0,op,
- "I don't know how to apply the %s.",query_name(tmp));
- }
- #endif
return 0;
}
return 1;
}
! /* Apply_Below attempts to apply the object 'below' the player (op).
* If the player has an open container, we use that for below, otherwise
* we use the ground.
*/
! void apply_below(object *op) {
object *tmp, *next;
/* If using a container, set the starting item to be the top
* item in the container. Otherwise, use the map.
*/
! if (op->container!=NULL) tmp=op->container->inv;
! else tmp=op->below;
/* This is perhaps more complicated. However, I want to make sure that
* we don't use a corrupt pointer for the next object, so we get the
--- 1871,1939 ----
case IDENTIFY_ALTAR:
return apply_id_altar(op, tmp);
default:
return 0;
}
return 1;
}
!
! /* quiet suppresses the "don't know how to apply" message as needed by
! * player_apply_below(). But there can still be "but you are floating high
! * above the ground" messages.
! *
! * Same return value as apply() function.
! */
! int player_apply (object *pl, object *op, int aflag, int quiet)
! {
! int tmp;
!
! if (op->env == NULL && QUERY_FLAG (pl, FLAG_FLYING))
! {
! /* player is flying and applying object not in inventory */
! if ( ! QUERY_FLAG (pl, FLAG_WIZ)
! && ! QUERY_FLAG (op, FLAG_FLYING)
! && ! QUERY_FLAG (op, FLAG_FLY_ON))
! {
! new_draw_info (NDI_UNIQUE, 0, pl, "But you are floating high "
! "above the ground!");
! return 0;
! }
! }
!
! if (QUERY_FLAG (op, FLAG_WAS_WIZ) && ! QUERY_FLAG (pl, FLAG_WAS_WIZ))
! {
! play_sound_map (pl->map, pl->x, pl->y, SOUND_OB_EVAPORATE);
! 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.");
! remove_ob (op);
! free_object (op);
! return 1;
! }
!
! pl->contr->last_used = op;
! pl->contr->last_used_id = op->count;
!
! tmp = apply (pl, op, aflag);
! if ( ! tmp && ! quiet)
! new_draw_info_format (NDI_UNIQUE, 0, pl, "I don't know how to apply "
! "the %s.", query_name (op));
! return tmp;
! }
!
! /* player_apply_below attempts to apply the object 'below' the player.
* If the player has an open container, we use that for below, otherwise
* we use the ground.
*/
! void player_apply_below (object *pl)
! {
object *tmp, *next;
/* If using a container, set the starting item to be the top
* item in the container. Otherwise, use the map.
*/
! tmp = (pl->container != NULL) ? pl->container->inv : pl->below;
/* This is perhaps more complicated. However, I want to make sure that
* we don't use a corrupt pointer for the next object, so we get the
***************
*** 1919,1925 ****
*/
for ( ; tmp!=NULL; tmp=next) {
next = tmp->below;
! if (apply(op, tmp, 0)) return;
if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
return; /* don't look below a floor */
}
--- 1943,1954 ----
*/
for ( ; tmp!=NULL; tmp=next) {
next = tmp->below;
! if ( ! tmp->invisible || QUERY_FLAG (tmp, FLAG_WALK_ON)
! || QUERY_FLAG (tmp, FLAG_FLY_ON))
! {
! if (player_apply (pl, tmp, 0, 1))
! return;
! }
if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
return; /* don't look below a floor */
}
diff -rc orig/crossfire-0.95.5-patch12/server/c_object.c crossfire-0.95.5/server/c_object.c
*** orig/crossfire-0.95.5-patch12/server/c_object.c Wed Mar 22 08:56:48 2000
--- crossfire-0.95.5/server/c_object.c Thu Apr 20 03:23:39 2000
***************
*** 198,231 ****
return change_skill(pl,skillno);
}
- void apply_inventory(object *op) {
- object *inv;
- if(op->contr->last_used!=NULL) {
- inv=op->contr->last_used;
- if(QUERY_FLAG(inv, FLAG_FREED)||inv->count!=op->contr->last_used_id||
- inv->env==NULL||(inv->env!=op&&inv->env->env!=op)) {
- op->contr->last_used=NULL;
- op->contr->last_used_id=0;
- apply_inventory(op);
- return;
- }
- } else {
- for (inv=op->inv; inv && inv->invisible; inv=inv->below) ;
- }
- if(inv) {
- if(!apply(op,inv,0)) {
- new_draw_info_format(NDI_UNIQUE, 0, op,
- "I don't know how to apply the %s.",query_name(inv));
- }
- } else {
- new_draw_info(NDI_UNIQUE, 0,op, "You have nothing to apply!");
- }
- }
-
int command_apply (object *op, char *params)
{
if (!params) {
! apply_below(op);
return 0;
}
else {
--- 198,207 ----
return change_skill(pl,skillno);
}
int command_apply (object *op, char *params)
{
if (!params) {
! player_apply_below(op);
return 0;
}
else {
***************
*** 245,254 ****
inv=find_best_object_match(op, params);
if (inv) {
! if(!apply(op,inv,aflag)) {
! new_draw_info_format(NDI_UNIQUE, 0, op,
! "I don't know how to apply the %s.",query_name(inv));
! }
} else
new_draw_info_format(NDI_UNIQUE, 0, op,
"Could not find any match to %s.",params);
--- 221,227 ----
inv=find_best_object_match(op, params);
if (inv) {
! player_apply(op,inv,aflag,0);
} else
new_draw_info_format(NDI_UNIQUE, 0, op,
"Could not find any match to %s.",params);
diff -rc orig/crossfire-0.95.5-patch12/socket/item.c crossfire-0.95.5/socket/item.c
*** orig/crossfire-0.95.5-patch12/socket/item.c Wed Mar 22 08:56:48 2000
--- crossfire-0.95.5/socket/item.c Thu Apr 20 03:24:24 2000
***************
*** 439,445 ****
pl->ob->name, tag);
return;
}
! apply (pl->ob, op,0);
}
/* Client wants to apply some object. Lets do so. */
--- 439,445 ----
pl->ob->name, tag);
return;
}
! player_apply (pl->ob, op, 0, 0);
}
/* Client wants to apply some object. Lets do so. */