/** * @brief Applies the data in the GUI to the entity. */ void EditEntityDialog::apply() { apply_simple_booleans(); apply_simple_integers(); apply_simple_strings(); apply_behavior(); apply_breed(); apply_damage_on_enemies(); apply_destination(); apply_destination_map(); apply_direction(); apply_font(); apply_ground(); apply_layer(); apply_maximum_moves(); apply_model(); apply_name(); apply_opening_method(); apply_rank(); apply_savegame_variable(); apply_size(); apply_sound(); apply_sprite(); apply_subtype(); apply_transition(); apply_treasure(); apply_type(); apply_weight(); apply_xy(); }
/** * Main apply handler. * * Checks for unpaid items before applying. * @param op ::object causing tmp to be applied. * @param tmp ::object being applied. * @param aflag Special (always apply/unapply) flags. Nothing is done * with them in this function - they are passed to apply_special(). * @retval 0 Player or monster can't apply objects of that type. * @retval 1 Has been applied, or there was an error applying the object. * @retval 2 Objects of that type can't be applied if not in * inventory. */ int manual_apply(object *op, object *tmp, int aflag) { if (tmp->head) { tmp = tmp->head; } if (op->type == PLAYER) { CONTR(op)->praying = 0; } if (QUERY_FLAG(tmp, FLAG_UNPAID) && !QUERY_FLAG(tmp, FLAG_APPLIED)) { if (op->type == PLAYER) { new_draw_info(NDI_UNIQUE, op, "You should pay for it first."); return 1; } /* Monsters just skip unpaid items */ else { return 0; } } /* Monsters must not apply random chests, nor magic_mouths with a counter */ if (op->type != PLAYER && tmp->type == TREASURE) { return 0; } /* Trigger the APPLY event */ if (!(aflag & AP_NO_EVENT) && trigger_event(EVENT_APPLY, op, tmp, NULL, NULL, aflag, 0, 0, SCRIPT_FIX_ACTIVATOR)) { return 1; } aflag &= ~AP_NO_EVENT; /* Control apply by controling a set exp object level or player exp level */ if (tmp->item_level) { int tmp_lev; if (tmp->item_skill) { tmp_lev = find_skill_exp_level(op, tmp->item_skill); } else { tmp_lev = op->level; } if (tmp->item_level > tmp_lev) { new_draw_info(NDI_UNIQUE, op, "The item level is too high to apply."); return 1; } } switch (tmp->type) { case HOLY_ALTAR: new_draw_info_format(NDI_UNIQUE, op, "You touch the %s.", tmp->name); if (change_skill(op, SK_PRAYING)) { pray_at_altar(op, tmp); } else { new_draw_info(NDI_UNIQUE, op, "Nothing happens. It seems you miss the right skill."); } return 1; break; case HANDLE: new_draw_info(NDI_UNIQUE, op, "You turn the handle."); play_sound_map(op->map, op->x, op->y, SOUND_TURN_HANDLE, SOUND_NORMAL); tmp->value = tmp->value ? 0 : 1; SET_ANIMATION(tmp, ((NUM_ANIMATIONS(tmp) / NUM_FACINGS(tmp)) * tmp->direction) + tmp->value); update_object(tmp, UP_OBJ_FACE); push_button(tmp); return 1; case TRIGGER: if (check_trigger(tmp, op)) { new_draw_info(NDI_UNIQUE, op, "You turn the handle."); play_sound_map(tmp->map, tmp->x, tmp->y, SOUND_TURN_HANDLE, SOUND_NORMAL); } else { new_draw_info(NDI_UNIQUE, op, "The handle doesn't move."); } return 1; case EXIT: if (op->type != PLAYER || !tmp->map) { return 0; } /* If no map path specified, we assume it is the map path of the exit. */ if (!EXIT_PATH(tmp)) { FREE_AND_ADD_REF_HASH(EXIT_PATH(tmp), tmp->map->path); } if (!EXIT_PATH(tmp) || !is_legal_2ways_exit(op, tmp) || (EXIT_Y(tmp) == -1 && EXIT_X(tmp) == -1)) { new_draw_info_format(NDI_UNIQUE, op, "The %s is closed.", query_name(tmp, NULL)); } else { /* Don't display messages for random maps. */ if (tmp->msg && strncmp(EXIT_PATH(tmp), "/!", 2) && strncmp(EXIT_PATH(tmp), "/random/", 8)) { new_draw_info(NDI_NAVY, op, tmp->msg); } enter_exit(op, tmp); } return 1; case SIGN: apply_sign(op, tmp); return 1; case BOOK: if (op->type == PLAYER) { apply_book(op, tmp); return 1; } return 0; case SKILLSCROLL: if (op->type == PLAYER) { apply_skillscroll(op, tmp); return 1; } return 0; case SPELLBOOK: if (op->type == PLAYER) { apply_spellbook(op, tmp); return 1; } return 0; case SCROLL: apply_scroll(op, tmp); return 1; case POTION: (void) apply_potion(op, tmp); return 1; case LIGHT_APPLY: apply_player_light(op, tmp); return 1; case LIGHT_REFILL: apply_player_light_refill(op, tmp); return 1; /* Eneq(@csd.uu.se): Handle apply on containers. */ case CLOSE_CON: if (op->type == PLAYER) { (void) esrv_apply_container(op, tmp->env); } return 1; case CONTAINER: if (op->type == PLAYER) { (void) esrv_apply_container(op, tmp); } return 1; case TREASURE: apply_treasure(op, tmp); return 1; case WEAPON: case ARMOUR: case BOOTS: case GLOVES: case AMULET: case GIRDLE: case BRACERS: case SHIELD: case HELMET: case RING: case CLOAK: case WAND: case ROD: case HORN: case SKILL: case BOW: case SKILL_ITEM: /* Not in inventory */ if (tmp->env != op) { return 2; } (void) apply_special(op, tmp, aflag); return 1; case DRINK: case FOOD: case FLESH: apply_food(op, tmp); return 1; case POISON: apply_poison(op, tmp); return 1; case SAVEBED: if (op->type == PLAYER) { apply_savebed(op); return 1; } return 0; case ARMOUR_IMPROVER: if (op->type == PLAYER) { apply_armour_improver(op, tmp); return 1; } return 0; case WEAPON_IMPROVER: apply_weapon_improver(op, tmp); return 1; case CLOCK: if (op->type == PLAYER) { timeofday_t tod; get_tod(&tod); new_draw_info_format(NDI_UNIQUE, op, "It is %d minute%s past %d o'clock %s", tod.minute + 1, ((tod.minute + 1 < 2) ? "" : "s"), ((tod.hour % (HOURS_PER_DAY / 2) == 0) ? (HOURS_PER_DAY / 2) : ((tod.hour) % (HOURS_PER_DAY / 2))), ((tod.hour >= (HOURS_PER_DAY / 2)) ? "pm" : "am")); return 1; } return 0; case POWER_CRYSTAL: apply_power_crystal(op, tmp); return 1; /* For lighting torches/lanterns/etc */ case LIGHTER: if (op->type == PLAYER) { apply_lighter(op, tmp); return 1; } return 0; /* So the below default case doesn't execute for these objects, * even if they have message. */ case DOOR: return 0; /* Nothing from the above... but show a message if it has one. */ default: if (tmp->msg) { new_draw_info(NDI_UNIQUE, op, tmp->msg); return 1; } return 0; } }