/** * @brief Updates this state. */ void Hero::VictoryState::update() { State::update(); if (System::now() >= end_victory_date) { get_map_script().event_hero_victory_sequence_finished(); } }
/** * @brief Activates this sensor. * * This function is called when the hero overlaps the sensor. * * @param hero the hero */ void Sensor::activate(Hero& hero) { if (!activated_by_hero) { activated_by_hero = true; switch (subtype) { case CUSTOM: // we notify the scripts notifying_script = true; get_map_script().event_hero_on_sensor(get_name()); notifying_script = false; get_hero().reset_movement(); break; case CHANGE_LAYER: // we change the hero's layer get_entities().set_entity_layer(hero, get_layer()); break; case RETURN_FROM_BAD_GROUND: // we indicate to the hero a location to return // after falling into a hole or some other ground get_hero().set_target_solid_ground_coords(get_xy(), get_layer()); break; } } else { if (subtype == CUSTOM && !notifying_script && !get_game().is_suspended()) { notifying_script = true; get_map_script().event_hero_still_on_sensor(get_name()); notifying_script = false; } } }
/** * @brief This function is called when this entity stops being moved by the * hero. */ void Block::stop_movement_by_hero() { clear_movement(); when_can_move = System::now() + moving_delay; // see if the block has moved if (get_x() != last_position.get_x() || get_y() != last_position.get_y()) { // the block has moved last_position.set_xy(get_x(), get_y()); // save the new position for next time if (maximum_moves == 1) { // if the block could be moved only once, maximum_moves = 0; // then it cannot move anymore } } // notify the script get_map_script().event_block_moved(get_name()); }
/** * @brief Updates the chest. * * This function is called repeatedly by the map. * This is a redefinition of MapEntity::update() * the handle the chest opening. */ void Chest::update() { if (is_open() && !suspended) { if (!treasure_given && treasure_date != 0 && System::now() >= treasure_date) { treasure_date = 0; if (treasure.get_item_name() != "_none") { // give a treasure to the player get_hero().start_treasure(treasure); treasure_given = true; } else { // the chest is empty // mark the treasure as found in the savegame int savegame_variable = treasure.get_savegame_variable(); if (savegame_variable != -1) { get_savegame().set_boolean(savegame_variable, true); } treasure_given = true; if (!get_map_script().event_chest_empty(get_name())) { // the script does not define any behavior: // by default, we tell the player the chest is empty Sound::play("wrong"); get_dialog_box().start_dialog("_empty_chest"); get_hero().start_free(); } } } } MapEntity::update(); }
/** * @brief This function is called when an explosion detects a collision with this entity. * @param explosion an explosion * @param collision_mode the collision mode that detected the collision */ void Sensor::notify_collision_with_explosion(Explosion& explosion, CollisionMode collision_mode) { if (subtype == CUSTOM && collision_mode == COLLISION_RECTANGLE) { get_map_script().event_sensor_collision_explosion(get_name()); } }