Пример #1
0
bool vehicle_part::is_fuel_store( bool skip_broke ) const
{
    if( skip_broke && is_broken() ) {
        return false;
    }
    return is_tank() || base.is_magazine() || is_reactor();
}
Пример #2
0
void component_worker::error_if_broken(std::unique_lock<std::mutex>& lock) const
{
	if (is_broken()) {
		std::string msg(__func__);
		msg += ": ";
		msg += get_name();
		msg += ": interrupted.";
		throw mf::interrupted_error(msg);
	}
}
Пример #3
0
bool vehicle_part::set_crew( const npc &who )
{
    if( who.is_dead_state() || !who.is_friend() ) {
        return false;
    }
    if( is_broken() || ( !is_seat() && !is_turret() ) ) {
        return false;
    }
    crew_id = who.getID();
    return true;
}
Пример #4
0
void component_worker::wait_restart_done()
{
	scoped_log_begin;
	std::unique_lock<std::mutex> lock(mut);

	cond.wait(lock, [&]() {
			return is_broken() || !is_running() || is_restart_done();
		});
	f_restart_done = false;
	error_if_broken(lock);
}
Пример #5
0
npc *vehicle_part::crew() const
{
    if( is_broken() || crew_id < 0 ) {
        return nullptr;
    }

    npc *const res = g->critter_by_id<npc>( crew_id );
    if( !res ) {
        return nullptr;
    }
    return res->is_friend() ? res : nullptr;
}
Пример #6
0
/*
 * Return a "feeling" (or NULL) about an item.  Method 1 (Heavy).
 */
s16b object_type::pseudo_heavy()
{
    /* Artifacts */
    if (is_artifact())
    {
        /* Cursed/Broken */
        if (is_cursed() || is_broken()) return (INSCRIP_TERRIBLE);

        /* Normal */
        return (INSCRIP_SPECIAL);
    }

    /* Ego-Items */
    if (is_ego_item())
    {
        /* Cursed/Broken */
        if (is_cursed() || is_broken()) return (INSCRIP_WORTHLESS);

        /* Normal */
        return (INSCRIP_EXCELLENT);
    }

    /* Cursed items */
    if (is_cursed()) return (INSCRIP_CURSED);

    /* Broken items */
    if (is_broken()) return (INSCRIP_BROKEN);

    /* Good "armor" bonus */
    if (to_a > 0) return (INSCRIP_GOOD_STRONG);

    /* Good "weapon" bonus */
    if (to_h + to_d > 0) return (INSCRIP_GOOD_STRONG);

    /* Default to "average" */
    return (INSCRIP_AVERAGE);
}
Пример #7
0
/*
 * Return a "feeling" (or NULL) about an item.  Method 2 (Light).
 */
s16b object_type::pseudo_light()
{
    /* Cursed items (all of them) */
    if (is_cursed()) return (INSCRIP_CURSED);

    /* Broken items (all of them) */
    if (is_broken()) return (INSCRIP_BROKEN);

    /* Artifacts -- except cursed/broken ones */
    if (is_artifact()) return (INSCRIP_GOOD_WEAK);

    /* Ego-Items -- except cursed/broken ones */
    if (is_ego_item()) return (INSCRIP_GOOD_WEAK);

    /* Good armor bonus */
    if (to_a > 0) return (INSCRIP_GOOD_WEAK);

    /* Good weapon bonuses */
    if (to_h + to_d > 0) return (INSCRIP_GOOD_WEAK);

    /* Default to "average" */
    return (INSCRIP_AVERAGE);
}
Пример #8
0
/**
 * \brief Notifies this entity that it has just failed to change its position
 * because of obstacles.
 */
void CarriedItem::notify_obstacle_reached() {

  if (is_throwing && !is_broken()) {
    break_item();
  }
}
Пример #9
0
/**
 * \brief This function is called repeatedly.
 */
void CarriedItem::update() {

  // update the sprite and the position
  Entity::update();

  if (is_suspended()) {
    return;
  }

  // when the hero finishes lifting the item, start carrying it
  if (is_lifting && get_movement()->is_finished()) {
    is_lifting = false;

    // make the item follow the hero
    clear_movement();
    set_movement(std::make_shared<RelativeMovement>(
        std::static_pointer_cast<Hero>(hero.shared_from_this()),
        0,
        -18,
        true
    ));
  }

  // when the item has finished flying, destroy it
  else if (can_explode() && !is_breaking) {

    uint32_t now = System::now();

    if (now >= explosion_date) {
      break_item();
    }
    else if (will_explode_soon()) {

      std::string animation = get_sprite().get_current_animation();
      if (animation == "stopped") {
        get_sprite().set_current_animation("stopped_explosion_soon");
      }
      else if (animation == "walking") {
        get_sprite().set_current_animation("walking_explosion_soon");
      }
    }
  }

  if (is_broken()) {
    remove_from_map();
  }
  else if (is_throwing) {
    shadow_sprite->update();

    if (break_one_layer_above) {
      break_item();
      int layer = get_layer();
      if (layer != get_map().get_highest_layer()) {
        get_entities().set_entity_layer(*this, layer + 1);
      }
      break_one_layer_above = false;
    }
    else if (get_movement()->is_stopped() || y_increment >= 7) {
      // Interrupt the movement.
      break_item_on_ground();
    }
    else {
      uint32_t now = System::now();
      while (now >= next_down_date) {
        next_down_date += 40;
        item_height -= y_increment;
        y_increment++;
      }
    }
  }
}
Пример #10
0
	void network_trainer::train(
		structured_data_bunch_reader& reader,
		network_data_peeker& peeker,
		network_data_pusher& progress_pusher,
		network_data_pusher& pusher)
	{
		initialize_train(reader);

		while(true)
		{
			network_data_peek_entry entry_peeked = peeker.peek(schema);
			if (entry_peeked.data == 0)
				break;

			training_task_state new_task;
			new_task.index_peeked = entry_peeked.index;
			new_task.data = entry_peeked.data;
			new_task.initial_epoch = entry_peeked.start_epoch;

			bool empty_momentum1 = false;
			if (momentum.is_momentum_data())
			{
				if (entry_peeked.momentum_data)
					new_task.momentum_data = entry_peeked.momentum_data;
				else
				{
					new_task.momentum_data = network_data::ptr(new network_data(schema->get_layers()));
					if (new_task.initial_epoch > 0)
						empty_momentum1 = true;
				}
			}
			else
				new_task.momentum_data = network_data::ptr();

			bool empty_momentum2 = false;
			if (momentum.is_momentum_data2())
			{
				if (entry_peeked.momentum_data2)
					new_task.momentum_data2 = entry_peeked.momentum_data2;
				else
				{
					new_task.momentum_data2 = network_data::ptr(new network_data(schema->get_layers()));
					if (new_task.initial_epoch > 0)
						empty_momentum2 = true;
				}
			}
			else
				new_task.momentum_data2 = network_data::ptr();

			
			if (is_last_epoch(new_task))
			{
				std::cout << "Warning: Task is allocated which is already complete. Index " << new_task.index_peeked << ", Base epoch " << new_task.initial_epoch << std::endl;
				continue;
			}

			std::cout << "New task allocated: Index " << new_task.index_peeked << ", Base epoch " << new_task.initial_epoch;
			if (empty_momentum1)
				std::cout << ", Starting with the 1st empty momentum";
			if (empty_momentum2)
				std::cout << ", Starting with the 2nd empty momentum";
			std::cout << std::endl;

			unsigned int reader_epoch_id = new_task.initial_epoch;

			while(true)
			{
				std::cout << "---------- NN # " << new_task.index_peeked << ", Epoch " << new_task.get_current_epoch() + 1 << " ----------" << std::endl;

				reader.set_epoch(reader_epoch_id);

				train_step(
					reader,
					new_task);

				++reader_epoch_id;

				progress_pusher.push(new_task, *schema);

				if (is_broken(new_task))
				{
					std::cout << "# " << new_task.index_peeked << " - broken weights while training, discarding it." << std::endl;
					break;
				}

				if (is_last_epoch(new_task))
				{
					pusher.push(new_task, *schema);
					break;
				}
			}
		}
	}
Пример #11
0
/**
 * @brief This function is called repeatedly.
 */
void CarriedItem::update() {

  // update the sprite and the position
  MapEntity::update();

  if (suspended) {
    return;
  }

  // when the hero finishes lifting the item, start carrying it
  if (is_lifting && get_movement()->is_finished()) {
    is_lifting = false;

    // make the item follow the hero
    clear_movement();
    set_movement(new FollowMovement(&hero, 0, -18, true));
  }

  // when the item has finished flying, destroy it
  else if (can_explode() && !is_breaking) {
    
    uint32_t now = System::now();
    
    if (now >= explosion_date) {
      break_item();
    }
    else if (will_explode_soon()) {

      std::string animation = get_sprite().get_current_animation();
      if (animation == "stopped") {
        get_sprite().set_current_animation("stopped_explosion_soon");
      }
      else if (animation == "walking") {
        get_sprite().set_current_animation("walking_explosion_soon");
      }
    }
  }

  if (is_throwing) {
    shadow_sprite->update();

    if (is_broken()) {
      remove_from_map();
    }
    else if (break_on_intermediate_layer) {
      break_item();
      get_entities().set_entity_layer(*this, LAYER_INTERMEDIATE);
      break_on_intermediate_layer = false;
    }
    else if (get_movement()->is_stopped() || y_increment >= 7) {
      break_item();
    }
    else {
      uint32_t now = System::now();
      while (now >= next_down_date) {
        next_down_date += 40;
        item_height -= y_increment;
        y_increment++;
      }
    }
  }
}
Пример #12
0
bool vehicle_part::is_unavailable( const bool carried ) const
{
    return is_broken() || ( has_flag( carried_flag ) && carried );
}