version 1.40 | | version 1.41 |
---|
| | |
/* | | /* |
* static char *rcsid_apply_c = | | * static char *rcsid_apply_c = |
* "$Id: apply.c,v 1.40 2001/06/11 18:47:21 michtoen Exp $"; | | * "$Id: apply.c,v 1.41 2001/06/13 10:51:20 michtoen Exp $"; |
*/ | | */ |
/* | | /* |
CrossFire, A Multiplayer game for X-windows | | CrossFire, A Multiplayer game for X-windows |
| | |
case TRIGGER_BUTTON: | | case TRIGGER_BUTTON: |
case TRIGGER_PEDESTAL: | | case TRIGGER_PEDESTAL: |
case TRIGGER_ALTAR: | | case TRIGGER_ALTAR: |
| | /* GROS: Handle for script_trigger event */ |
| | if (trap->script_trigger != NULL) |
| | { |
| | guile_call_event(victim, trap, NULL, 0, NULL,0,0,trap->script_trigger, SCRIPT_FIX_ALL); |
| | } |
| | else |
| | { |
| | if (trap->script_str_trigger != NULL) |
| | { |
| | guile_call_event_str(victim, trap, NULL, 0, NULL,0,0,trap->script_str_trigger, SCRIPT_FIX_ALL); |
| | } |
| | else |
| | { |
check_trigger (trap, victim); | | check_trigger (trap, victim); |
| | } |
| | }; |
goto leave; | | goto leave; |
| | |
case DEEP_SWAMP: | | case DEEP_SWAMP: |
| | |
goto leave; | | goto leave; |
| | |
case CHECK_INV: | | case CHECK_INV: |
| | /* GROS: Handle for script_trigger event */ |
| | if (trap->script_trigger != NULL) |
| | { |
| | guile_call_event(victim, trap, NULL, 0, NULL,0,0,trap->script_trigger, SCRIPT_FIX_ALL); |
| | } |
| | else |
| | { |
| | if (trap->script_str_trigger != NULL) |
| | { |
| | guile_call_event_str(victim, trap, NULL, 0, NULL,0,0,trap->script_str_trigger, SCRIPT_FIX_ALL); |
| | } |
| | else |
| | { |
check_inv (victim, trap); | | check_inv (victim, trap); |
| | } |
| | }; |
goto leave; | | goto leave; |
| | |
case HOLE: | | case HOLE: |
| | |
*/ | | */ |
if (trap->msg && strncmp(EXIT_PATH(trap),"/!",2) && strncmp(EXIT_PATH(trap), "/random/", 8)) | | if (trap->msg && strncmp(EXIT_PATH(trap),"/!",2) && strncmp(EXIT_PATH(trap), "/random/", 8)) |
new_draw_info (NDI_NAVY, 0, victim, trap->msg); | | new_draw_info (NDI_NAVY, 0, victim, trap->msg); |
| | /* GROS: Handle for script_trigger event */ |
| | if (trap->script_trigger != NULL) |
| | { |
| | guile_call_event(victim, trap, NULL, 0, NULL,0,0,trap->script_trigger, SCRIPT_FIX_ALL); |
| | } |
| | else |
| | { |
| | if (trap->script_str_trigger != NULL) |
| | { |
| | guile_call_event_str(victim, trap, NULL, 0, NULL,0,0,trap->script_str_trigger, SCRIPT_FIX_ALL); |
| | } |
| | }; |
enter_exit (victim, trap); | | enter_exit (victim, trap); |
} | | } |
goto leave; | | goto leave; |
| | |
| | |
case RUNE: | | case RUNE: |
if (trap->level && QUERY_FLAG (victim, FLAG_ALIVE)) | | if (trap->level && QUERY_FLAG (victim, FLAG_ALIVE)) |
| | { |
| | /* GROS: Handle for script_trigger event */ |
| | if (trap->script_trigger != NULL) |
| | { |
| | guile_call_event(victim, trap, NULL, 0, NULL,0,0,trap->script_trigger, SCRIPT_FIX_ALL); |
| | } |
| | else |
| | { |
| | if (trap->script_str_trigger != NULL) |
| | { |
| | guile_call_event_str(victim, trap, NULL, 0, NULL,0,0,trap->script_str_trigger, SCRIPT_FIX_ALL); |
| | } |
| | else |
| | { |
spring_trap (trap, victim); | | spring_trap (trap, victim); |
| | } |
| | }; |
| | }; |
goto leave; | | goto leave; |
| | |
default: | | default: |
| | |
| | |
new_draw_info_format (NDI_UNIQUE, 0, op, | | new_draw_info_format (NDI_UNIQUE, 0, op, |
"You open the %s and start reading.", tmp->name); | | "You open the %s and start reading.", tmp->name); |
| | |
| | /* GROS: Handling for reading scripted books */ |
| | if (tmp->script_apply != NULL) |
| | { |
| | guile_call_event(op,tmp, NULL, 0, NULL,0,0,tmp->script_apply, SCRIPT_FIX_ALL); |
| | } |
| | else |
| | { |
| | if (tmp->script_str_apply != NULL) |
| | { |
| | guile_call_event_str(op,tmp, NULL, 0, NULL,0,0,tmp->script_str_apply, SCRIPT_FIX_ALL); |
| | } |
| | else |
new_draw_info(NDI_UNIQUE | NDI_NAVY, 0, op, tmp->msg); | | new_draw_info(NDI_UNIQUE | NDI_NAVY, 0, op, tmp->msg); |
| | }; |
| | |
/* gain xp from reading */ | | /* gain xp from reading */ |
if(!QUERY_FLAG(tmp,FLAG_NO_SKILL_IDENT)) { /* only if not read before */ | | if(!QUERY_FLAG(tmp,FLAG_NO_SKILL_IDENT)) { /* only if not read before */ |
| | |
decrease_ob(tmp); | | decrease_ob(tmp); |
} | | } |
| | |
| | /* is_legal_2ways_exit (object* op, object *exit) |
| | * this fonction return true if the exit |
| | * is not a 2 ways one or it is 2 ways, valid exit. |
| | * A valid 2 way exit means: |
| | * -You can come back (there is another exit at the other side) |
| | * -You are |
| | * ° the owner of the exit |
| | * ° or in the same party as the owner |
| | * |
| | * Note: a owner in a 2 way exit is saved as the owner's name |
| | * in the field exit->name cause the field exit->owner doesn't |
| | * survive in the swapping (in fact the whole exit doesn't survive). |
| | */ |
| | int is_legal_2ways_exit (object* op, object *exit) |
| | { |
| | object * tmp; |
| | object * exit_owner; |
| | player * pp; |
| | mapstruct * exitmap; |
| | if (exit->stats.exp!=1) return 1; /*This is not a 2 way, so it is legal*/ |
| | /* To know if an exit has a correspondant, we look at |
| | * all the exits in destination and try to find one with same path as |
| | * the current exit's position */ |
| | if (!strncmp(EXIT_PATH (exit), settings.localdir, strlen(settings.localdir))) |
| | exitmap = ready_map_name(EXIT_PATH (exit), MAP_PLAYER_UNIQUE); |
| | else exitmap = ready_map_name(EXIT_PATH (exit), 0); |
| | if (exitmap) |
| | { |
| | tmp=get_map_ob (exitmap,EXIT_X(exit),EXIT_Y(exit)); |
| | if (!tmp) return 0; |
| | for ( (tmp=get_map_ob(exitmap,EXIT_X(exit),EXIT_Y(exit)));tmp;tmp=tmp->above) |
| | { |
| | if (tmp->type!=EXIT) continue; /*Not an exit*/ |
| | if (!EXIT_PATH (tmp)) continue; /*Not a valid exit*/ |
| | if ( (EXIT_X(tmp)!=exit->x) || (EXIT_Y(tmp)!=exit->y)) continue; /*Not in the same place*/ |
| | if (strcmp(exit->map->path,EXIT_PATH(tmp))!=0) continue; /*Not in the same map*/ |
| | |
| | /* From here we have found the exit is valid. However we do |
| | * here the check of the exit owner. It is important for the |
| | * town portals to prevent strangers from visiting your appartments |
| | */ |
| | if (!exit->race) return 1; /*No owner, free for all!*/ |
| | exit_owner=NULL; |
| | for (pp=first_player;pp;pp=pp->next) |
| | { |
| | if (!pp->ob) continue; |
| | if (pp->ob->name!=exit->race) continue; |
| | exit_owner= pp->ob; /*We found a player which correspond to the player name*/ |
| | break; |
| | } |
| | if (!exit_owner) return 0; /* No more owner*/ |
| | if (exit_owner->contr==op->contr) return 1; /*It is your exit*/ |
| | if ( exit_owner && /*There is a owner*/ |
| | (op->contr) && /*A player tries to pass */ |
| | ( (exit_owner->contr->party_number<=0) || /*No pass if controller has no party*/ |
| | (exit_owner->contr->party_number!=op->contr->party_number)) ) /* Or not the same as op*/ |
| | return 0; |
| | return 1; |
| | } |
| | } |
| | return 0; |
| | } |
| | |
/* Return value: | | /* Return value: |
* 0: player or monster can't apply objects of that type | | * 0: player or monster can't apply objects of that type |
| | |
| | |
int manual_apply (object *op, object *tmp, int aflag) | | int manual_apply (object *op, object *tmp, int aflag) |
{ | | { |
| | int rtn_script; |
if (QUERY_FLAG (tmp, FLAG_UNPAID) && ! QUERY_FLAG (tmp, FLAG_APPLIED)) { | | if (QUERY_FLAG (tmp, FLAG_UNPAID) && ! QUERY_FLAG (tmp, FLAG_APPLIED)) { |
if (op->type == PLAYER) { | | if (op->type == PLAYER) { |
new_draw_info (NDI_UNIQUE, 0, op, "You should pay for it first."); | | new_draw_info (NDI_UNIQUE, 0, op, "You should pay for it first."); |
| | |
return 0; /* monsters just skip unpaid items */ | | return 0; /* monsters just skip unpaid items */ |
} | | } |
} | | } |
| | /* GROS: This is used to handle apply scripts */ |
| | if (tmp->script_apply!=NULL) |
| | { |
| | rtn_script = guile_call_event(op,tmp, NULL, aflag, NULL,0,0,tmp->script_apply, SCRIPT_FIX_ALL); |
| | if (rtn_script!=0) return; |
| | }; |
| | if (tmp->script_str_apply!=NULL) |
| | { |
| | rtn_script = guile_call_event_str(op,tmp, NULL, aflag, NULL,0,0,tmp->script_str_apply, SCRIPT_FIX_ALL); |
| | if (rtn_script!=0) return; |
| | }; |
| | |
switch (tmp->type) | | switch (tmp->type) |
{ | | { |
| | |
case EXIT: | | case EXIT: |
if (op->type != PLAYER) | | if (op->type != PLAYER) |
return 0; | | return 0; |
if( ! EXIT_PATH (tmp)) { | | if( ! EXIT_PATH (tmp) || !is_legal_2ways_exit(op,tmp)) { |
new_draw_info_format(NDI_UNIQUE, 0, op, | | new_draw_info_format(NDI_UNIQUE, 0, op, |
"The %s is closed.",query_name(tmp)); | | "The %s is closed.",query_name(tmp)); |
} else { | | } else { |
| | |
if(op->env!=who) | | if(op->env!=who) |
return 1; /* op is not in inventory */ | | return 1; /* op is not in inventory */ |
| | |
| | /* GROS: This is used to handle apply scripts */ |
| | if (op->script_apply!=NULL) |
| | { |
| | guile_call_event(who,op, NULL, aflags, NULL,0,0,op->script_apply, SCRIPT_FIX_ALL); |
| | }; |
| | if (op->script_str_apply!=NULL) |
| | { |
| | guile_call_event_str(who,op, NULL, aflags, NULL,0,0,op->script_str_apply, SCRIPT_FIX_ALL); |
| | }; |
| | |
buf[0]='\0'; /* Needs to be initialized */ | | buf[0]='\0'; /* Needs to be initialized */ |
if (QUERY_FLAG(op,FLAG_APPLIED)) { | | if (QUERY_FLAG(op,FLAG_APPLIED)) { |
/* always apply, so no reason to unapply */ | | /* always apply, so no reason to unapply */ |
| | |
(void) check_skill_to_apply(who,op); | | (void) check_skill_to_apply(who,op); |
if(QUERY_FLAG(who,FLAG_READY_WEAPON)) | | if(QUERY_FLAG(who,FLAG_READY_WEAPON)) |
CLEAR_FLAG(who,FLAG_READY_WEAPON); | | CLEAR_FLAG(who,FLAG_READY_WEAPON); |
| | /* GROS: update the current_weapon_script field (used with script_attack for weapons) */ |
| | who->current_weapon_script = NULL; |
| | who->current_weapon = NULL; |
sprintf(buf,"You unwield %s.",query_name(op)); | | sprintf(buf,"You unwield %s.",query_name(op)); |
break; | | break; |
| | |
| | |
SET_FLAG(who, FLAG_READY_WEAPON); | | SET_FLAG(who, FLAG_READY_WEAPON); |
| | |
(void) change_abil (who,op); | | (void) change_abil (who,op); |
| | /* GROS: update the current_weapon_script field (used with script_attack for weapons) */ |
| | if ((op->script_attack != NULL)|(op->script_str_attack != NULL)) |
| | { |
| | LOG(llevDebug, "Scripting Weapon wielded\n"); |
| | if (who->current_weapon_script) free_string(who->current_weapon_script); |
| | who->current_weapon_script=add_string(query_name(op)); |
| | who->current_weapon = op; |
| | }; |
sprintf(buf,"You wield %s.",query_name(op)); | | sprintf(buf,"You wield %s.",query_name(op)); |
break; | | break; |
} | | } |