/**
 * @brief Initializes the sound field.
 */
void EditEntityDialog::initialize_sound() {

  QString field_name;
  if (entity_before.has_field(sound_field_name)) {
    field_name = sound_field_name;
  }
  else if (entity_before.has_field(destruction_sound_field_name)) {
    ui.sound_checkbox->setText(tr("Play a sound when destroyed"));
    field_name = destruction_sound_field_name;
  }
  else {
    remove_field(ui.sound_checkbox, ui.sound_field);
    return;
  }

  ui.sound_field->set_quest(get_quest());
  ui.sound_field->set_resource_type(ResourceType::SOUND);
  initialize_possibly_optional_field(
        field_name,
        nullptr,
        nullptr,
        ui.sound_checkbox,
        ui.sound_field);
  QString sound = entity_before.get_field(field_name).toString();
  ui.sound_field->set_selected_id(sound);
}
/**
 * @brief Initializes the treasure field.
 */
void EditEntityDialog::initialize_treasure() {

  if (!entity_before.has_field(treasure_name_field_name) ||
      !entity_before.has_field(treasure_variant_field_name) ||
      !entity_before.has_field(treasure_savegame_variable_field_name)
  ) {
    remove_field(ui.treasure_label, ui.treasure_layout);
    return;
  }

  ui.treasure_name_field->set_quest(get_quest());
  ui.treasure_name_field->set_resource_type(ResourceType::ITEM);
  ui.treasure_name_field->add_special_value("", tr("(None)"), 0);  // Add the special value "None".

  // Only accept valid identifiers as savegame variable names.
  ui.treasure_savegame_variable_field->setValidator(create_savegame_variable_validator());

  QString treasure_name = entity_before.get_field(treasure_name_field_name).toString();
  ui.treasure_name_field->set_selected_id(treasure_name);
  ui.treasure_variant_field->setValue(entity_before.get_field(treasure_variant_field_name).toInt());
  QString treasure_savegame_variable = entity_before.get_field(treasure_savegame_variable_field_name).toString();
  if (treasure_savegame_variable.isEmpty()) {
    ui.treasure_savegame_variable_label->setEnabled(false);
    ui.treasure_savegame_variable_field->setEnabled(false);
  }
  else {
    ui.treasure_savegame_variable_field->setText(treasure_savegame_variable);
    ui.save_treasure_checkbox->setChecked(true);
  }
  connect(ui.save_treasure_checkbox, SIGNAL(toggled(bool)),
          ui.treasure_savegame_variable_label, SLOT(setEnabled(bool)));
  connect(ui.save_treasure_checkbox, SIGNAL(toggled(bool)),
          ui.treasure_savegame_variable_field, SLOT(setEnabled(bool)));
}
/**
 * @brief Initializes the size fields.
 */
void EditEntityDialog::initialize_size() {

  if (!entity_before.has_size_fields()) {
    remove_field(ui.size_label, ui.size_field);
    return;
  }

  // Initialize spinboxes.
  ui.size_field->config("x", 8, 999999);

  // Show the current size in the spinboxes.
  ui.size_field->set_size(entity_before.get_size());

  // Tell spinboxes to only make multiples of the base size.
  const QSize& base_size = entity_before.get_base_size();
  ui.size_field->set_first_step(base_size.width());
  ui.size_field->set_first_min(base_size.width());
  ui.size_field->set_second_step(base_size.height());
  ui.size_field->set_second_min(base_size.height());

  // Apply the resize mode contraints.
  update_size_constraints();

  connect(ui.size_field, SIGNAL(first_value_changed(int)),
          this, SLOT(width_changed(int)));
  connect(ui.size_field, SIGNAL(second_value_changed(int)),
          this, SLOT(height_changed(int)));
}
/**
 * @brief Initializes the savegame variable field.
 */
void EditEntityDialog::initialize_savegame_variable() {

  if (!entity_before.has_field(savegame_variable_field_name)) {
    remove_field(ui.savegame_variable_checkbox, ui.savegame_variable_layout);
    return;
  }

  // Specific checkbox text for some types of entities.
  const QMap<EntityType, QString> checkbox_texts = {
    { EntityType::ENEMY, tr("Save the enemy state") },
    { EntityType::DOOR, tr("Save the door state") }
  };
  QString checkbox_text = checkbox_texts.value(entity_before.get_type());
  if (!checkbox_text.isEmpty()) {
    ui.savegame_variable_checkbox->setText(checkbox_text);
  }

  // Connect the checkbox to the field.
  initialize_possibly_optional_field(
        savegame_variable_field_name,
        nullptr,
        nullptr,
        ui.savegame_variable_checkbox,
        ui.savegame_variable_layout);

  // Only accept valid identifiers as savegame variable names.
  ui.savegame_variable_field->setValidator(create_savegame_variable_validator());

  // Show the initial value.
  QString value = entity_before.get_field(savegame_variable_field_name).toString();
  ui.savegame_variable_field->setText(value);
}
/**
 * @brief Initializes the name field.
 */
void EditEntityDialog::initialize_name() {

  if (!entity_before.is_dynamic()) {
    remove_field(ui.name_label, ui.name_field);
    return;
  }

  ui.name_field->setText(entity_before.get_name());
  ui.name_field->setValidator(create_name_validator());
}
/**
 * @brief Initializes the transition field.
 */
void EditEntityDialog::initialize_transition() {

  if (!entity_before.has_field(transition_field_name)) {
    remove_field(ui.transition_label, ui.transition_field);
    return;
  }

  QString transition_name = entity_before.get_field(transition_field_name).toString();
  ui.transition_field->set_selected_value(TransitionTraits::get_by_lua_name(transition_name));
}
/**
 * @brief Initializes the behavior fields.
 */
void EditEntityDialog::initialize_behavior() {

  if (!entity_before.has_field(behavior_field_name)) {
    remove_field(ui.behavior_label, ui.behavior_layout);
    return;
  }

  ui.behavior_item_field->set_quest(get_quest());
  ui.behavior_item_field->set_resource_type(ResourceType::ITEM);

  ui.behavior_dialog_field->setEnabled(false);
  connect(ui.behavior_dialog_radio, SIGNAL(toggled(bool)),
          ui.behavior_dialog_field, SLOT(setEnabled(bool)));
  ui.behavior_item_field->setEnabled(false);
  connect(ui.behavior_item_radio, SIGNAL(toggled(bool)),
          ui.behavior_item_field, SLOT(setEnabled(bool)));

  QString behavior = entity_before.get_field(behavior_field_name).toString();
  // behavior can be one of:
  // - "map",
  // - "dialog#xxx" where xxx is a dialog id,
  // - "item#xxx" where xxx is an item id.

  QStringList parts = behavior.split('#');
  if (parts.size() == 2) {
    QString first = parts.at(0);
    if (first == "dialog") {
      // Show a dialog.
      QString dialog_id = parts.at(1);
      ui.behavior_dialog_radio->setChecked(true);
      ui.behavior_dialog_field->setText(dialog_id);
      ui.behavior_dialog_field->setEnabled(true);
    }
    else if (first == "item") {
      // Call an item script.
      QString item_id = parts.at(1);
      ui.behavior_item_radio->setChecked(true);
      ui.behavior_item_field->set_selected_id(item_id);
      ui.behavior_item_field->setEnabled(true);
    }
    else {
      // The field is invalid: initialize the dialog with "map".
      behavior = "map";
    }
  }
  else if (behavior != "map") {
    // The field is invalid: initialize the dialog with "map".
    behavior = "map";
  }

  if (behavior == "map") {
    // Call the map script.
    ui.behavior_map_radio->setChecked(true);
  }
}
/**
 * @brief Initializes the breed field.
 */
void EditEntityDialog::initialize_breed() {

  if (!entity_before.has_field(breed_field_name)) {
    remove_field(ui.breed_label, ui.breed_field);
    return;
  }

  ui.breed_field->set_quest(get_quest());
  ui.breed_field->set_resource_type(ResourceType::ENEMY);
  QString breed = entity_before.get_field(breed_field_name).toString();
  ui.breed_field->set_selected_id(breed);
}
/**
 * @brief Initializes the font field.
 */
void EditEntityDialog::initialize_font() {

  if (!entity_before.has_field(font_field_name)) {
    remove_field(ui.font_label, ui.font_field);
    return;
  }

  ui.font_field->set_quest(get_quest());
  ui.font_field->set_resource_type(ResourceType::FONT);
  ui.font_field->add_special_value("", tr("(Default)"), 0);
  QString font = entity_before.get_field(font_field_name).toString();
  ui.font_field->set_selected_id(font);
}
/**
 * @brief Initializes the direction field.
 */
void EditEntityDialog::initialize_direction() {

  if (!entity_before.has_direction_field()) {
    remove_field(ui.direction_label, ui.direction_layout);
    return;
  }

  int num_directions = entity_before.get_num_directions();
  if (entity_before.is_no_direction_allowed()) {
    ui.direction_field->addItem(entity_before.get_no_direction_text(), -1);
  }

  QStringList texts;
  if (num_directions == 4) {
    texts = QStringList{
      tr("Right"),
      tr("Up"),
      tr("Left"),
      tr("Down")
    };
  }
  else if (num_directions == 8) {
    texts = QStringList{
      tr("Right"),
      tr("Right-up"),
      tr("Up"),
      tr("Left-up"),
      tr("Left"),
      tr("Left-down"),
      tr("Down"),
      tr("Right-down"),
    };
  }
  else {
    for (int i = 0; i < num_directions; ++num_directions) {
      texts.append(QString::number(i));
    }
  }
  for (int i = 0; i < texts.size(); ++i) {
    ui.direction_field->addItem(texts[i], i);
  }

  int index = entity_before.get_direction();
  if (entity_before.is_no_direction_allowed()) {
    ++index;
  }
  ui.direction_field->setCurrentIndex(index);

  connect(ui.direction_field, SIGNAL(currentIndexChanged(int)),
          this, SLOT(direction_changed()));
}
/**
 * @brief Initializes the weight field.
 */
void EditEntityDialog::initialize_weight() {

  if (!entity_before.has_field(weight_field_name)) {
    remove_field(ui.weight_checkbox, ui.weight_layout);
    return;
  }

  initialize_possibly_optional_field(
        weight_field_name,
        nullptr,
        nullptr,
        ui.weight_checkbox,
        ui.weight_field);
  ui.weight_field->setValue(entity_before.get_field(weight_field_name).toInt());
}
/**
 * @brief Initializes the rank field.
 */
void EditEntityDialog::initialize_rank() {

  if (!entity_before.has_field(rank_field_name)) {
    remove_field(ui.rank_label, ui.rank_field);
    return;
  }

  ui.rank_field->addItem(tr("Normal"), 0);
  ui.rank_field->addItem(tr("Miniboss"), 1);
  ui.rank_field->addItem(tr("Boss"), 2);

  int value = entity_before.get_field(rank_field_name).toInt();
  int index = ui.rank_field->findData(value);
  if (index != -1) {
    ui.rank_field->setCurrentIndex(index);
  }
}
/**
 * @brief Initializes the maximum moves field.
 */
void EditEntityDialog::initialize_maximum_moves() {

  if (!entity_before.has_field(maximum_moves_field_name)) {
    remove_field(ui.maximum_moves_label, ui.maximum_moves_field);
    return;
  }

  ui.maximum_moves_field->addItem(tr("Cannot move"), 0);
  ui.maximum_moves_field->addItem(tr("1 move only"), 1);
  ui.maximum_moves_field->addItem(tr("Unlimited"), 2);

  int value = entity_before.get_field(maximum_moves_field_name).toInt();
  int index = ui.maximum_moves_field->findData(value);
  if (index != -1) {
    ui.maximum_moves_field->setCurrentIndex(index);
  }
}
/**
 * @brief Initializes the ground field.
 */
void EditEntityDialog::initialize_ground() {

  if (!entity_before.has_field(ground_field_name)) {
    remove_field(ui.ground_checkbox, ui.ground_field);
    return;
  }

  initialize_possibly_optional_field(
        ground_field_name,
        nullptr,
        nullptr,
        ui.ground_checkbox,
        ui.ground_field);

  QString ground_name = entity_before.get_field(ground_field_name).toString();
  ui.ground_field->set_selected_value(GroundTraits::get_by_lua_name(ground_name));
}
/**
 * @brief Initializes the destination map field.
 */
void EditEntityDialog::initialize_destination_map() {

  if (!entity_before.has_field(destination_map_field_name)) {
    remove_field(ui.destination_map_label, ui.destination_map_field);
    return;
  }

  ui.destination_map_field->set_quest(get_quest());
  ui.destination_map_field->set_resource_type(ResourceType::MAP);
  ui.destination_map_field->set_selected_id(entity_before.get_field(destination_map_field_name).toString());

  connect(ui.destination_map_field, &QComboBox::currentTextChanged, [&](const QString&) {
    QString map_id = ui.destination_map_field->currentData().toString();
    ui.destination_field->set_map_id(get_quest(), map_id);
    ui.destination_field->build();
  });
}
/**
 * @brief Initializes the destination field.
 */
void EditEntityDialog::initialize_destination() {

  if (!entity_before.has_field(destination_field_name)) {
    remove_field(ui.destination_label, ui.destination_field);
    return;
  }

  QString destination_map_id = entity_before.get_field(destination_map_field_name).toString();
  ui.destination_field->set_map_id(get_quest(), destination_map_id);
  ui.destination_field->set_filtered_by_entity_type(true);
  ui.destination_field->set_entity_type_filter(EntityType::DESTINATION);
  ui.destination_field->add_special_value("", tr("(Default destination)"));
  ui.destination_field->add_special_value("_same", tr("(Same point)"));
  ui.destination_field->add_special_value("_side", tr("(Side of the map)"));
  ui.destination_field->build();
  ui.destination_field->set_selected_name(entity_before.get_field(destination_field_name).toString());
}
/**
 * @brief Initializes the model field.
 */
void EditEntityDialog::initialize_model() {

  if (!entity_before.has_field(model_field_name)) {
    remove_field(ui.model_checkbox, ui.model_field);
    return;
  }

  initialize_possibly_optional_field(
        model_field_name,
        nullptr,
        nullptr,
        ui.model_checkbox,
        ui.model_field);
  ui.model_field->set_quest(get_quest());
  ui.model_field->set_resource_type(ResourceType::ENTITY);
  QString model = entity_before.get_field(model_field_name).toString();
  ui.model_field->set_selected_id(model);
}
/**
 * @brief Initializes the subtype field.
 */
void EditEntityDialog::initialize_subtype() {

  if (!entity_before.has_subtype_field()) {
    remove_field(ui.subtype_label, ui.subtype_field);
    return;
  }

  int i = 0;
  const SubtypeList& subtypes = entity_before.get_existing_subtypes();
  for (const QPair<QString, QString>& subtype : subtypes) {
    ui.subtype_field->addItem(subtype.second, subtype.first);

    if (entity_before.get_subtype() == subtype.first) {
      ui.subtype_field->setCurrentIndex(i);
    }
    ++i;
  }
}
/**
 * @brief Initializes the damage on enemies field.
 */
void EditEntityDialog::initialize_damage_on_enemies() {

  if (!entity_before.has_field(damage_on_enemies_field_name)) {
    remove_field(ui.damage_on_enemies_checkbox, ui.damage_on_enemies_layout);
    return;
  }

  int damage_on_enemies = entity_before.get_field(damage_on_enemies_field_name).toInt();
  ui.damage_on_enemies_field->setValue(damage_on_enemies);

  if (damage_on_enemies == 0) {
    ui.damage_on_enemies_field->setEnabled(false);
  }
  else {
    ui.damage_on_enemies_checkbox->setChecked(true);
  }
  connect(ui.damage_on_enemies_checkbox, SIGNAL(toggled(bool)),
          ui.damage_on_enemies_field, SLOT(setEnabled(bool)));
}
/**
 * @brief Initializes the sprite field.
 */
void EditEntityDialog::initialize_sprite() {

  if (!entity_before.has_field(sprite_field_name)) {
    remove_field(ui.sprite_label_checkbox, ui.sprite_field);
    return;
  }

  initialize_possibly_optional_field(
        sprite_field_name,
        ui.sprite_label_checkbox->layout(),
        ui.sprite_label,
        ui.sprite_checkbox,
        ui.sprite_field);
  ui.sprite_field->set_resource_type(ResourceType::SPRITE);
  ui.sprite_field->set_quest(get_quest());
  ui.sprite_field->set_tileset_id(get_map().get_tileset_id());
  QString sprite = entity_before.get_field(sprite_field_name).toString();
  ui.sprite_field->set_selected_id(sprite);
}
/**
 * @brief Updates the entity from the opening method fields.
 */
void EditEntityDialog::apply_opening_method() {

  if (!entity_before.has_field(opening_method_field_name) ||
      !entity_before.has_field(opening_condition_field_name) ||
      !entity_before.has_field(opening_condition_consumed_field_name)) {
    remove_field(ui.opening_method_label, ui.opening_method_layout);
    return;
  }

  entity_after->set_field(opening_method_field_name, get_selected_opening_method());

  if (ui.opening_method_savegame_variable_radio->isChecked()) {
    entity_after->set_field(opening_condition_field_name, ui.opening_condition_savegame_variable_field->text());
    entity_after->set_field(opening_condition_consumed_field_name, ui.opening_condition_savegame_variable_consumed_checkbox->isChecked());
  }
  else if (ui.opening_method_item_radio->isChecked()) {
    entity_after->set_field(opening_condition_field_name, ui.opening_condition_item_field->get_selected_id());
    entity_after->set_field(opening_condition_consumed_field_name, ui.opening_condition_item_consumed_checkbox->isChecked());
  }
}
void map::step_in_field(int x, int y, game *g)
{
 field *cur = &field_at(x, y);
 int veh_part;
 vehicle *veh = NULL;
 bool inside = false;
 int adjusted_intensity;

 if (g->u.in_vehicle) {
  veh = g->m.veh_at(x, y, veh_part);
  inside = (veh && veh->is_inside(veh_part));
 }

 switch (cur->type) {
  case fd_null:
  case fd_blood:	// It doesn't actually do anything
  case fd_bile:		// Ditto
   return;

  case fd_web: {
   if (!g->u.has_trait(PF_WEB_WALKER) && !g->u.in_vehicle) {
    int web = cur->density * 5 - g->u.disease_level(DI_WEBBED);
    if (web > 0)
     g->u.add_disease(DI_WEBBED, web, g);
    remove_field(x, y);
   }
  } break;

  case fd_acid:
   if (cur->density == 3 && !inside) {
    g->add_msg("The acid burns your legs and feet!");
    g->u.hit(g, bp_feet, 0, 0, rng(4, 10));
    g->u.hit(g, bp_feet, 1, 0, rng(4, 10));
    g->u.hit(g, bp_legs, 0, 0, rng(2,  8));
    g->u.hit(g, bp_legs, 1, 0, rng(2,  8));
   }
   break;

 case fd_sap:
  if( g->u.in_vehicle ) break;
  g->add_msg("The sap sticks to you!");
  g->u.add_disease(DI_SAP, cur->density * 2, g);
  if (cur->density == 1)
   remove_field(x, y);
  else
   cur->density--;
  break;

  case fd_fire:
   adjusted_intensity = cur->density;
   if( g->u.in_vehicle )
     if( inside )
       adjusted_intensity -= 2;
     else
       adjusted_intensity -= 1;
   if (!g->u.has_active_bionic(bio_heatsink)) {
    if (adjusted_intensity == 1) {
     g->add_msg("You burn your legs and feet!");
     g->u.hit(g, bp_feet, 0, 0, rng(2, 6));
     g->u.hit(g, bp_feet, 1, 0, rng(2, 6));
     g->u.hit(g, bp_legs, 0, 0, rng(1, 4));
     g->u.hit(g, bp_legs, 1, 0, rng(1, 4));
    } else if (adjusted_intensity == 2) {
     g->add_msg("You're burning up!");
     g->u.hit(g, bp_legs, 0, 0,  rng(2, 6));
     g->u.hit(g, bp_legs, 1, 0,  rng(2, 6));
     g->u.hit(g, bp_torso, 0, 4, rng(4, 9));
    } else if (adjusted_intensity == 3) {
     g->add_msg("You're set ablaze!");
     g->u.hit(g, bp_legs, 0, 0, rng(2, 6));
     g->u.hit(g, bp_legs, 1, 0, rng(2, 6));
     g->u.hit(g, bp_torso, 0, 4, rng(4, 9));
     g->u.add_disease(DI_ONFIRE, 5, g);
    }
    if (adjusted_intensity == 2)
     g->u.infect(DI_SMOKE, bp_mouth, 5, 20, g);
    else if (adjusted_intensity == 3)
     g->u.infect(DI_SMOKE, bp_mouth, 7, 30, g);
   }
   break;

  case fd_smoke:
   if (cur->density == 3 && !inside)
    g->u.infect(DI_SMOKE, bp_mouth, 4, 15, g);
   break;

  case fd_tear_gas:
   if ((cur->density > 1 || !one_in(3)) && !inside || inside && one_in(3))
    g->u.infect(DI_TEARGAS, bp_mouth, 5, 20, g);
   if (cur->density > 1 && !inside || inside && one_in(3))
    g->u.infect(DI_BLIND, bp_eyes, cur->density * 2, 10, g);
   break;

  case fd_toxic_gas:
   if (cur->density == 2 && !inside || cur->density == 3 && inside )
    g->u.infect(DI_POISON, bp_mouth, 5, 30, g);
   else if (cur->density == 3 && !inside)
    g->u.infect(DI_BADPOISON, bp_mouth, 5, 30, g);
   break;

  case fd_nuke_gas:
   g->u.radiation += rng(0, cur->density * (cur->density + 1));
   if (cur->density == 3) {
    g->add_msg("This radioactive gas burns!");
    g->u.hurtall(rng(1, 3));
   }
   break;

  case fd_flame_burst:
   if (inside) break;
   if (!g->u.has_active_bionic(bio_heatsink)) {
    g->add_msg("You're torched by flames!");
    g->u.hit(g, bp_legs, 0, 0,  rng(2, 6));
    g->u.hit(g, bp_legs, 1, 0,  rng(2, 6));
    g->u.hit(g, bp_torso, 0, 4, rng(4, 9));
   } else
    g->add_msg("These flames do not burn you.");
   break;

  case fd_electricity:
   if (g->u.has_artifact_with(AEP_RESIST_ELECTRICITY))
    g->add_msg("The electricity flows around you.");
   else {
    g->add_msg("You're electrocuted!");
    g->u.hurtall(rng(1, cur->density));
    if (one_in(8 - cur->density) && !one_in(30 - g->u.str_cur)) {
     g->add_msg("You're paralyzed!");
     g->u.moves -= rng(cur->density * 50, cur->density * 150);
    }
   }
   break;

  case fd_fatigue:
   if (rng(0, 2) < cur->density) {
    g->add_msg("You're violently teleported!");
    g->u.hurtall(cur->density);
    g->teleport();
   }
   break;

  case fd_shock_vent:
  case fd_acid_vent:
   remove_field(x, y);
   break;
 }
}
Exemple #23
0
void map::step_in_field(int x, int y, game *g)
{
 field *cur = &field_at(x, y);
 switch (cur->type) {
  case fd_null:
  case fd_blood:	// It doesn't actually do anything
  case fd_bile:		// Ditto
   return;

  case fd_web: {
   if (!g->u.has_trait(PF_WEB_WALKER)) {
    int web = cur->density * 5 - g->u.disease_level(DI_WEBBED);
    if (web > 0)
     g->u.add_disease(DI_WEBBED, web, g);
    remove_field(x, y);
   }
  } break;

  case fd_acid:
   if (cur->density == 3 && !g->u.has_trait(PF_ACID_IMMUNE)) {
    g->add_msg("The acid burns your legs and feet!");
    g->u.hit(g, bp_feet, 0, 0, rng(4, 10));
    g->u.hit(g, bp_feet, 1, 0, rng(4, 10));
    g->u.hit(g, bp_legs, 0, 0, rng(2,  8));
    g->u.hit(g, bp_legs, 1, 0, rng(2,  8));
   } else {
       if (!g->u.has_trait(PF_ACID_RESIST)) {
    g->add_msg("The acid burns your feet!");
    g->u.hit(g, bp_feet, 0, 0, rng(cur->density, 4 * cur->density));
    g->u.hit(g, bp_feet, 1, 0, rng(cur->density, 4 * cur->density));
   }
   }
   break;

 case fd_sap:
  g->add_msg("The sap sticks to you!");
  g->u.add_disease(DI_SAP, cur->density * 2, g);
  if (cur->density == 1)
   remove_field(x, y);
  else
   cur->density--;
  break;

  case fd_fire:
   if (!g->u.has_active_bionic(bio_heatsink)) {
    if (cur->density == 1) {
     g->add_msg("You burn your legs and feet!");
     g->u.hit(g, bp_feet, 0, 0, rng(2, 6));
     g->u.hit(g, bp_feet, 1, 0, rng(2, 6));
     g->u.hit(g, bp_legs, 0, 0, rng(1, 4));
     g->u.hit(g, bp_legs, 1, 0, rng(1, 4));
    } else if (cur->density == 2) {
     g->add_msg("You're burning up!");
     g->u.hit(g, bp_legs, 0, 0,  rng(2, 6));
     g->u.hit(g, bp_legs, 1, 0,  rng(2, 6));
     g->u.hit(g, bp_torso, 0, 4, rng(4, 9));
    } else if (cur->density == 3) {
     g->add_msg("You're set ablaze!");
     g->u.hit(g, bp_legs, 0, 0, rng(2, 6));
     g->u.hit(g, bp_legs, 1, 0, rng(2, 6));
     g->u.hit(g, bp_torso, 0, 4, rng(4, 9));
     g->u.add_disease(DI_ONFIRE, 5, g);
    }
    if (cur->density == 2)
     g->u.infect(DI_SMOKE, bp_mouth, 5, 20, g);
    else if (cur->density == 3)
     g->u.infect(DI_SMOKE, bp_mouth, 7, 30, g);
   }
   break;

  case fd_smoke:
   if (cur->density == 3)
    g->u.infect(DI_SMOKE, bp_mouth, 4, 15, g);
   break;

  case fd_tear_gas:
   if (cur->density > 1 || !one_in(3))
    g->u.infect(DI_TEARGAS, bp_mouth, 5, 20, g);
   if (cur->density > 1)
    g->u.infect(DI_BLIND, bp_eyes, cur->density * 2, 10, g);
   break;

  case fd_toxic_gas:
   if (cur->density == 2)
    g->u.infect(DI_POISON, bp_mouth, 5, 30, g);
   else if (cur->density == 3)
    g->u.infect(DI_BADPOISON, bp_mouth, 5, 30, g);
   break;

  case fd_nuke_gas:
   g->u.radiation += rng(0, cur->density * (cur->density + 1));
   if (cur->density == 3) {
    g->add_msg("This radioactive gas burns!");
    g->u.hurtall(rng(1, 3));
   }
   break;

  case fd_flame_burst:
   g->add_msg("You're torched by flames!");
   g->u.hit(g, bp_legs, 0, 0,  rng(2, 6));
   g->u.hit(g, bp_legs, 1, 0,  rng(2, 6));
   g->u.hit(g, bp_torso, 0, 4, rng(4, 9));
   break;

  case fd_electricity:
   g->add_msg("You're electrocuted!");
   g->u.hurtall(rng(1, cur->density));
   if (one_in(8 - cur->density) && !one_in(30 - g->u.str_cur)) {
    g->add_msg("You're paralyzed!");
    g->u.moves -= cur->density * 150;
   }
   break;

  case fd_fatigue:
   if (rng(0, 2) < cur->density) {
    g->add_msg("You're violently teleported!");
    g->u.hurtall(cur->density);
    g->teleport();
   }
   break;
 }
}
Exemple #24
0
void map::mon_in_field(int x, int y, game *g, monster *z)
{
 if (z->has_flag(MF_DIGS))
  return;	// Digging monsters are immune to fields
 field *cur = &field_at(x, y);
 int dam = 0;
 switch (cur->type) {
  case fd_null:
  case fd_blood:	// It doesn't actually do anything
  case fd_bile:		// Ditto
   break;

  case fd_web:
   if (!z->has_flag(MF_WEBWALK)) {
    z->speed *= .8;
    remove_field(x, y);
   }

  case fd_acid:
   if (!z->has_flag(MF_DIGS) && !z->has_flag(MF_FLIES) &&
       !z->has_flag(MF_ACIDPROOF)) {
    if (cur->density == 3)
     dam = rng(4, 10) + rng(2, 8);
    else
     dam = rng(cur->density, cur->density * 4);
   }
   break;

  case fd_sap:
   z->speed -= cur->density * 5;
   if (cur->density == 1)
    remove_field(x, y);
   else
    cur->density--;
   break;

  case fd_fire:
   if (z->made_of(FLESH))
    dam = 3;
   if (z->made_of(VEGGY))
    dam = 12;
   if (z->made_of(PAPER) || z->made_of(LIQUID) || z->made_of(POWDER) ||
       z->made_of(WOOD)  || z->made_of(COTTON) || z->made_of(WOOL))
    dam = 50;
   if (z->made_of(STONE) || z->made_of(KEVLAR) || z->made_of(STEEL))
    dam = -25;
   if (z->has_flag(MF_FLIES))
    dam -= 20;

   if (cur->density == 1)
    dam += rng(0, 8);
   else if (cur->density == 2) {
    dam += rng(3, 12);
    if (!z->has_flag(MF_FLIES)) {
     z->moves -= 20;
     if (!z->made_of(LIQUID) && !z->made_of(STONE) && !z->made_of(KEVLAR) &&
         !z->made_of(STEEL) && !z->has_flag(MF_FIREY))
      z->add_effect(ME_ONFIRE, rng(3, 8));
    }
   } else if (cur->density == 3) {
    dam += rng(5, 18);
    if (!z->has_flag(MF_FLIES) || one_in(3)) {
     z->moves -= 40;
     if (!z->made_of(LIQUID) && !z->made_of(STONE) && !z->made_of(KEVLAR) &&
         !z->made_of(STEEL) && !z->has_flag(MF_FIREY))
      z->add_effect(ME_ONFIRE, rng(8, 12));
    }
   }
   break;

  case fd_smoke:
   if (cur->density == 3)
    z->speed -= rng(10, 20);
   if (z->made_of(VEGGY))	// Plants suffer from smoke even worse
    z->speed -= rng(1, cur->density * 12);
   break;

  case fd_tear_gas:
   if (z->made_of(FLESH) || z->made_of(VEGGY)) {
    z->add_effect(ME_BLIND, cur->density * 8);
    if (cur->density == 3) {
     z->add_effect(ME_STUNNED, rng(10, 20));
     dam = rng(4, 10);
    } else if (cur->density == 2) {
     z->add_effect(ME_STUNNED, rng(5, 10));
     dam = rng(2, 5);
    } else
     z->add_effect(ME_STUNNED, rng(1, 5));
    if (z->made_of(VEGGY)) {
     z->speed -= rng(cur->density * 5, cur->density * 12);
     dam += cur->density * rng(8, 14);
    }
   }
   break;

  case fd_toxic_gas:
   dam = cur->density;
   z->speed -= cur->density;
   break;

  case fd_nuke_gas:
   if (cur->density == 3) {
    z->speed -= rng(60, 120);
    dam = rng(30, 50);
   } else if (cur->density == 2) {
    z->speed -= rng(20, 50);
    dam = rng(10, 25);
   } else {
    z->speed -= rng(0, 15);
    dam = rng(0, 12);
   }
   if (z->made_of(VEGGY)) {
    z->speed -= rng(cur->density * 5, cur->density * 12);
    dam *= cur->density;
   }
   break;

  case fd_flame_burst:
   if (z->made_of(FLESH))
    dam = 3;
   if (z->made_of(VEGGY))
    dam = 12;
   if (z->made_of(PAPER) || z->made_of(LIQUID) || z->made_of(POWDER) ||
       z->made_of(WOOD)  || z->made_of(COTTON) || z->made_of(WOOL))
    dam = 50;
   if (z->made_of(STONE) || z->made_of(KEVLAR) || z->made_of(STEEL))
    dam = -25;
   dam += rng(0, 8);
   z->moves -= 20;
   break;

  case fd_electricity:
   dam = rng(1, cur->density);
   if (one_in(8 - cur->density))
    z->moves -= cur->density * 150;
   break;

  case fd_fatigue:
   if (rng(0, 2) < cur->density) {
    dam = cur->density;
    int tries = 0;
    int newposx, newposy;
    do {
     newposx = rng(z->posx - SEEX, z->posx + SEEX);
     newposy = rng(z->posy - SEEY, z->posy + SEEY);
     tries++;
    } while (g->m.move_cost(newposx, newposy) == 0 && tries != 10);

    if (tries == 10)
     g->explode_mon(g->mon_at(z->posx, z->posy));
    else {
     int mon_hit = g->mon_at(newposx, newposy), t;
     if (mon_hit != -1) {
      if (g->u_see(z, t))
       g->add_msg("The %s teleports into a %s, killing them both!",
                  z->name().c_str(), g->z[mon_hit].name().c_str());
      g->explode_mon(mon_hit);
     } else {
      z->posx = newposx;
      z->posy = newposy;
     }
    }
   }
   break;

 }
 if (dam > 0)
  z->hurt(dam);
}
/**
 * @brief Initializes the opening method fields.
 */
void EditEntityDialog::initialize_opening_method() {

  if (!entity_before.has_field(opening_method_field_name) ||
      !entity_before.has_field(opening_condition_field_name) ||
      !entity_before.has_field(opening_condition_consumed_field_name)) {
    remove_field(ui.opening_method_label, ui.opening_method_layout);
    return;
  }

  // Some entity types don't have all values: remove such fields.
  hide_unexisting_opening_methods();

  // Initialize the item selector.
  ui.opening_condition_item_field->set_resource_type(ResourceType::ITEM);
  ui.opening_condition_item_field->set_quest(get_quest());

  // Put the current values into the widgets.
  // opening_method is how to open the chest or door,
  // opening_condition is the required savegame variable or item id depending on the method.
  QString opening_method = entity_before.get_field(opening_method_field_name).toString();
  QString opening_condition = entity_before.get_field(opening_condition_field_name).toString();
  bool opening_condition_consumed = entity_before.get_field(opening_condition_consumed_field_name).toBool();

  // Check the correct radio button.
  const QMap<QString, QRadioButton*>& radios = get_opening_method_radio_buttons();
  QRadioButton* radio = radios.value(opening_method);
  if (radio != nullptr) {
    radio->setChecked(true);
  }
  else {
    // Check a default radio button if the current value is invalid.
    ui.opening_method_interaction_radio->setChecked(true);
  }

  // Prepare the savegame variable fields.
  if (radio == ui.opening_method_savegame_variable_radio) {
    ui.opening_condition_savegame_variable_field->setText(opening_condition);
    ui.opening_condition_savegame_variable_consumed_checkbox->setChecked(opening_condition_consumed);
  }
  else {
    ui.opening_condition_savegame_variable_field->setEnabled(false);
    ui.opening_condition_savegame_variable_consumed_checkbox->setEnabled(false);
  }
  connect(ui.opening_method_savegame_variable_radio, SIGNAL(toggled(bool)),
          ui.opening_condition_savegame_variable_field, SLOT(setEnabled(bool)));
  connect(ui.opening_method_savegame_variable_radio, SIGNAL(toggled(bool)),
          ui.opening_condition_savegame_variable_consumed_checkbox, SLOT(setEnabled(bool)));

  // Prepare the item fields.
  if (radio == ui.opening_method_item_radio) {
    ui.opening_condition_item_field->set_selected_id(opening_condition);
    ui.opening_condition_item_consumed_checkbox->setChecked(opening_condition_consumed);
  }
  else {
    ui.opening_condition_item_field->setEnabled(false);
    ui.opening_condition_item_consumed_checkbox->setEnabled(false);
  }
  connect(ui.opening_method_item_radio, SIGNAL(toggled(bool)),
          ui.opening_condition_item_field, SLOT(setEnabled(bool)));
  connect(ui.opening_method_item_radio, SIGNAL(toggled(bool)),
          ui.opening_condition_item_consumed_checkbox, SLOT(setEnabled(bool)));
}