From d7c60e9cb4fb01f26cfa1c8354078ab93ae062e7 Mon Sep 17 00:00:00 2001 From: Aaron Chancey Date: Tue, 19 Jul 2022 22:22:28 -0400 Subject: [PATCH] Immobile Monsters Can't Wander (#59421) * Immobile Monsters Can't Wander This adds a check for the immobile flag to ensure immobile monsters (like the trapped tendril) won't get picked up in hordes. * Astyle fixes Someone else didn't run astyle~ --- object_creator/creator_main.cpp | 9 +- object_creator/creator_main_window.cpp | 24 +++--- object_creator/dual_list_box.cpp | 6 +- object_creator/spell_window.cpp | 115 +++++++++++++------------ src/monster.cpp | 3 + 5 files changed, 83 insertions(+), 74 deletions(-) diff --git a/object_creator/creator_main.cpp b/object_creator/creator_main.cpp index 94b95ee2b765f..af5cbef7cc8fd 100644 --- a/object_creator/creator_main.cpp +++ b/object_creator/creator_main.cpp @@ -110,10 +110,10 @@ int main( int argc, char *argv[] ) PATH_INFO::set_standard_filenames(); MAP_SHARING::setDefaults(); - + QSettings settings( QSettings::IniFormat, QSettings::UserScope, - "CleverRaven", "Cataclysm - DDA" ); - + "CleverRaven", "Cataclysm - DDA" ); + cli_opts cli; @@ -149,8 +149,7 @@ int main( int argc, char *argv[] ) mods.push_back( mod_id( "dda" ) ); if( settings.contains( "mods/include" ) ) { QStringList modlist = settings.value( "mods/include" ).value(); - for( const QString& i : modlist ) - { + for( const QString &i : modlist ) { mods.push_back( mod_id( i.toStdString() ) ); } } diff --git a/object_creator/creator_main_window.cpp b/object_creator/creator_main_window.cpp index 547fb7953a5be..b2482d2f13c44 100644 --- a/object_creator/creator_main_window.cpp +++ b/object_creator/creator_main_window.cpp @@ -32,7 +32,7 @@ int creator::main_window::execute( QApplication &app ) { const int default_text_box_height = 20; const int default_text_box_width = 100; - const QSize default_text_box_size(default_text_box_width, default_text_box_height); + const QSize default_text_box_size( default_text_box_width, default_text_box_height ); int row = 0; int col = 0; @@ -45,7 +45,7 @@ int creator::main_window::execute( QApplication &app ) //Does nothing on it's own but once settings.setvalue() is called it will create //an ini file in C:\Users\User\AppData\Roaming\CleverRaven or equivalent directory QSettings settings( QSettings::IniFormat, QSettings::UserScope, - "CleverRaven", "Cataclysm - DDA" ); + "CleverRaven", "Cataclysm - DDA" ); // ========================================================================================= @@ -54,14 +54,14 @@ int creator::main_window::execute( QApplication &app ) QLabel mods_label; mods_label.setParent( &title_menu ); mods_label.setText( QString( "Select mods (restart required):" ) ); - mods_label.resize( default_text_box_size*2 ); + mods_label.resize( default_text_box_size * 2 ); mods_label.move( QPoint( col * default_text_box_width, row++ * default_text_box_height ) ); mods_label.show(); row++; //We always load 'dda' so we exclude it from the mods list QStringList all_mods; - for( const mod_id& e : world_generator->get_mod_manager().all_mods() ) { + for( const mod_id &e : world_generator->get_mod_manager().all_mods() ) { if( !e->obsolete && e->ident.str() != "dda" ) { all_mods.append( e->ident.c_str() ); } @@ -75,8 +75,8 @@ int creator::main_window::execute( QApplication &app ) mods_box.show(); //The user's mod selection gets saved to a file QObject::connect( &mods_box, &dual_list_box::pressed, [&]() { - settings.setValue( "mods/include", mods_box.get_included() ); - }); + settings.setValue( "mods/include", mods_box.get_included() ); + } ); //A previous selection of mods is loaded from disk and applied to the modlist widget if( settings.contains( "mods/include" ) ) { @@ -89,10 +89,10 @@ int creator::main_window::execute( QApplication &app ) QPushButton spell_button( _( "Spell Creator" ), &title_menu ); spell_button.move( QPoint( col * default_text_box_width, row * default_text_box_height ) ); QObject::connect( &spell_button, &QPushButton::released, - [&]() { - title_menu.hide(); - spell_editor.show(); - }); + [&]() { + title_menu.hide(); + spell_editor.show(); + } ); @@ -103,8 +103,8 @@ int creator::main_window::execute( QApplication &app ) col += 6; max_row = std::max( max_row, row ); max_col = std::max( max_col, col ); - title_menu.resize( QSize( ( max_col + 1) * default_text_box_width, - ( max_row )*default_text_box_height ) ); + title_menu.resize( QSize( ( max_col + 1 ) * default_text_box_width, + ( max_row )*default_text_box_height ) ); return app.exec(); diff --git a/object_creator/dual_list_box.cpp b/object_creator/dual_list_box.cpp index 34c37835b99a1..a27f0f4453b29 100644 --- a/object_creator/dual_list_box.cpp +++ b/object_creator/dual_list_box.cpp @@ -114,10 +114,10 @@ void creator::dual_list_box::include_selected() } excluded_box.clear(); excluded_box.addItems( excluded ); - if ( excluded.isEmpty() ) { + if( excluded.isEmpty() ) { return; } - if ( index > excluded_box.count() - 1 ) { + if( index > excluded_box.count() - 1 ) { index = excluded_box.count() - 1; } excluded_box.item( index )->setSelected( true ); @@ -164,7 +164,7 @@ QStringList creator::dual_list_box::get_included() const void creator::dual_list_box::set_included( const QStringList ret ) { - if( included_box.count() > 0 ){ + if( included_box.count() > 0 ) { exclude_all(); } for( int y = 0; y < ret.count(); y++ ) { diff --git a/object_creator/spell_window.cpp b/object_creator/spell_window.cpp index 993efee89ec63..1d76ce0a4cbdb 100644 --- a/object_creator/spell_window.cpp +++ b/object_creator/spell_window.cpp @@ -50,19 +50,21 @@ creator::spell_window::spell_window( QWidget *parent, Qt::WindowFlags flags ) // first column of boxes (just the spell list) spell_items_box.setParent( this ); spell_items_box.resize( QSize( default_text_box_width * 2, default_text_box_height * 30 ) ); - spell_items_box.move( QPoint( col * default_text_box_width, row * default_text_box_height) ); + spell_items_box.move( QPoint( col * default_text_box_width, row * default_text_box_height ) ); spell_items_box.setToolTip( QString( - _("Various spells, select one to see the details") ) ); + _( "Various spells, select one to see the details" ) ) ); spell_items_box.show(); - for( const spell_type& sp_t : spell_type::get_all() ) { - QListWidgetItem* new_item = new QListWidgetItem( + for( const spell_type &sp_t : spell_type::get_all() ) { + QListWidgetItem *new_item = new QListWidgetItem( QString( sp_t.id.c_str() ) ); spell_items_box.addItem( new_item ); } //When the user selects a spell from the spell list, populate the fields in the form. QObject::connect( &spell_items_box, &QListWidget::itemSelectionChanged, - [&]() { spell_window::populate_fields(); } ); + [&]() { + spell_window::populate_fields(); + } ); // ========================================================================================= @@ -153,7 +155,7 @@ creator::spell_window::spell_window( QWidget *parent, Qt::WindowFlags flags ) QObject::connect( &learn_spells_box, &QTableWidget::cellChanged, [&]() { { - if( learn_spells_box.selectedItems().length() > 0 ){ + if( learn_spells_box.selectedItems().length() > 0 ) { QTableWidgetItem *cur_widget = learn_spells_box.selectedItems().first(); const int cur_row = learn_spells_box.row( cur_widget ); QAbstractItemModel *model = learn_spells_box.model(); @@ -349,7 +351,7 @@ creator::spell_window::spell_window( QWidget *parent, Qt::WindowFlags flags ) casting_time_label.show(); duration_label.setParent( this ); - duration_label.setText( QString("duration") ); + duration_label.setText( QString( "duration" ) ); duration_label.resize( default_text_box_size ); duration_label.move( QPoint( col * default_text_box_width, row++ * default_text_box_height ) ); duration_label.show(); @@ -602,17 +604,17 @@ creator::spell_window::spell_window( QWidget *parent, Qt::WindowFlags flags ) min_duration_box.setParent( this ); min_duration_box.resize( default_text_box_size ); - min_duration_box.move( QPoint( col* default_text_box_width, row++* default_text_box_height ) ); + min_duration_box.move( QPoint( col * default_text_box_width, row++* default_text_box_height ) ); min_duration_box.setToolTip( QString( _( "The duration of the spell at level 0" ) ) ); min_duration_box.setMaximum( INT_MAX ); min_duration_box.show(); QObject::connect( &min_duration_box, &QSpinBox::textChanged, - [&]() { - editable_spell.min_duration = min_duration_box.value(); - max_duration_box.setValue(std::max(max_duration_box.value(), editable_spell.min_duration)); - editable_spell.min_duration = max_duration_box.value(); - write_json(); - } ); + [&]() { + editable_spell.min_duration = min_duration_box.value(); + max_duration_box.setValue( std::max( max_duration_box.value(), editable_spell.min_duration ) ); + editable_spell.min_duration = max_duration_box.value(); + write_json(); + } ); energy_source_box.setParent( this ); energy_source_box.resize( default_text_box_size ); @@ -729,7 +731,7 @@ creator::spell_window::spell_window( QWidget *parent, Qt::WindowFlags flags ) [&]() { std::string selected = components_box.currentText().toStdString(); requirement_id rq_components; - if( selected == "NONE") { + if( selected == "NONE" ) { editable_spell.spell_components = rq_components; } else { editable_spell.spell_components = requirement_id( selected ); @@ -962,16 +964,18 @@ creator::spell_window::spell_window( QWidget *parent, Qt::WindowFlags flags ) duration_increment_box.setParent( this ); duration_increment_box.resize( default_text_box_size ); - duration_increment_box.move( QPoint( col* default_text_box_width, row++* default_text_box_height ) ); - duration_increment_box.setToolTip( QString( _( "Amount of dot increased per level of the spell" ) ) ); + duration_increment_box.move( QPoint( col * default_text_box_width, + row++* default_text_box_height ) ); + duration_increment_box.setToolTip( QString( + _( "Amount of dot increased per level of the spell" ) ) ); duration_increment_box.setMaximum( INT_MAX ); duration_increment_box.setMinimum( INT_MIN ); duration_increment_box.show(); QObject::connect( &duration_increment_box, &QDoubleSpinBox::textChanged, - [&]() { - editable_spell.duration_increment = duration_increment_box.value(); - write_json(); - } ); + [&]() { + editable_spell.duration_increment = duration_increment_box.value(); + write_json(); + } ); affected_bps_label.setParent( this ); @@ -1158,18 +1162,18 @@ creator::spell_window::spell_window( QWidget *parent, Qt::WindowFlags flags ) max_duration_box.setParent( this ); max_duration_box.resize( default_text_box_size ); - max_duration_box.move( QPoint( col* default_text_box_width, row++* default_text_box_height ) ); + max_duration_box.move( QPoint( col * default_text_box_width, row++* default_text_box_height ) ); max_duration_box.setToolTip( QString( _( "The maximum duration the spell can achieve" ) ) ); max_duration_box.setMaximum( INT_MAX ); max_duration_box.setMinimum( INT_MIN ); max_duration_box.show(); QObject::connect( &max_duration_box, &QSpinBox::textChanged, - [&]() { - editable_spell.max_duration = max_duration_box.value(); - min_duration_box.setValue( std::min( min_duration_box.value(), max_duration_box.value() ) ); - editable_spell.min_duration = min_duration_box.value(); - write_json(); - } ); + [&]() { + editable_spell.max_duration = max_duration_box.value(); + min_duration_box.setValue( std::min( min_duration_box.value(), max_duration_box.value() ) ); + editable_spell.min_duration = min_duration_box.value(); + write_json(); + } ); affected_bps_box.setParent( this ); affected_bps_box.resize( QSize( default_text_box_width, default_text_box_height * 4 ) ); @@ -1325,20 +1329,21 @@ void creator::spell_window::write_json() void creator::spell_window::populate_fields() { - QListWidgetItem* editItem = spell_items_box.currentItem(); - const QString& s = editItem->text(); + QListWidgetItem *editItem = spell_items_box.currentItem(); + const QString &s = editItem->text(); - for( const spell_type& sp_t : spell_type::get_all() ) { + for( const spell_type &sp_t : spell_type::get_all() ) { if( sp_t.id.c_str() == s ) { - editable_spell.targeted_monster_ids = sp_t.targeted_monster_ids; //Need to set this first to output the right json later - - id_box.setText ( QString( sp_t.id.c_str() ) ); + editable_spell.targeted_monster_ids = + sp_t.targeted_monster_ids; //Need to set this first to output the right json later + + id_box.setText( QString( sp_t.id.c_str() ) ); name_box.setText( QString( sp_t.name.translated().c_str() ) ); description_box.setPlainText( QString( sp_t.description.translated().c_str() ) ); int index = effect_box.findText( sp_t.effect_name.c_str() ); - if ( index != -1 ) { + if( index != -1 ) { effect_box.setCurrentIndex( index ); } effect_str_box.setText( QString( sp_t.effect_str.c_str() ) ); @@ -1356,7 +1361,7 @@ void creator::spell_window::populate_fields() } for( int i = 0; i < static_cast( spell_flag::LAST ); i++ ) { - if( sp_t.spell_tags.test(static_cast( i ) ) ) { + if( sp_t.spell_tags.test( static_cast( i ) ) ) { spell_flags_box.item( i )->setCheckState( Qt::Checked ); } else { spell_flags_box.item( i )->setCheckState( Qt::Unchecked ); @@ -1366,16 +1371,16 @@ void creator::spell_window::populate_fields() editable_spell.learn_spells.clear(); learn_spells_box.clearContents(); - learn_spells_box.setRowCount(1); + learn_spells_box.setRowCount( 1 ); std::map l_spells = sp_t.learn_spells; if( !l_spells.empty() ) { for( std::map::iterator it = l_spells.begin(); - it != l_spells.end(); ++it ) { + it != l_spells.end(); ++it ) { learn_spells_box.insertRow( 0 ); int learn_at_level = it->second; const std::string learn_spell_id = it->first; - QTableWidgetItem* item = new QTableWidgetItem(); + QTableWidgetItem *item = new QTableWidgetItem(); item->setText( QString( learn_spell_id.c_str() ) ); learn_spells_box.setCurrentItem( item ); learn_spells_box.setItem( 0, 0, item ); @@ -1386,7 +1391,7 @@ void creator::spell_window::populate_fields() learn_spells_box.setItem( 0, 1, item ); } } - + base_energy_cost_box.setValue( sp_t.base_energy_cost ); final_energy_cost_box.setValue( sp_t.final_energy_cost ); @@ -1411,13 +1416,15 @@ void creator::spell_window::populate_fields() - index = energy_source_box.findText( QString( io::enum_to_string( sp_t.energy_source ).c_str() ) ); - if ( index != -1 ) { + index = energy_source_box.findText( QString( io::enum_to_string + ( sp_t.energy_source ).c_str() ) ); + if( index != -1 ) { energy_source_box.setCurrentIndex( index ); } - index = dmg_type_box.findText( QString( io::enum_to_string( sp_t.dmg_type ).c_str() ) ); - if ( index != -1 ) { + index = dmg_type_box.findText( QString( io::enum_to_string + ( sp_t.dmg_type ).c_str() ) ); + if( index != -1 ) { dmg_type_box.setCurrentIndex( index ); } @@ -1425,17 +1432,17 @@ void creator::spell_window::populate_fields() std::string cls = sp_t.spell_class.c_str(); if( cls != "" ) { index = spell_class_box.findText( QString( cls.c_str() ) ); - if ( index != -1 ) { + if( index != -1 ) { spell_class_box.setCurrentIndex( index ); } } else { index = spell_class_box.findText( QString( "NONE" ) ); - if ( index != -1 ) { + if( index != -1 ) { spell_class_box.setCurrentIndex( index ); } } - + difficulty_box.setValue( sp_t.difficulty ); max_level_box.setValue( sp_t.max_level ); spell_message_box.setText( QString( sp_t.message.translated().c_str() ) ); @@ -1444,7 +1451,7 @@ void creator::spell_window::populate_fields() std::string cmp = sp_t.spell_components.c_str(); if( cmp != "" ) { index = components_box.findText( QString( cmp.c_str() ) ); - if ( index != -1 ) { + if( index != -1 ) { components_box.setCurrentIndex( index ); } } else { @@ -1457,7 +1464,7 @@ void creator::spell_window::populate_fields() std::string skill = sp_t.skill.c_str(); if( skill != "" ) { index = skill_box.findText( QString( skill.c_str() ) ); - if ( index != -1 ) { + if( index != -1 ) { skill_box.setCurrentIndex( index ); } } else { @@ -1472,7 +1479,7 @@ void creator::spell_window::populate_fields() field_id_box.setCurrentIndex( field_id_box.findText( QString( "NONE" ) ) ); if( sp_t.field ) { index = field_id_box.findText( QString( field.c_str() ) ); - if ( index != -1 ) { + if( index != -1 ) { field_id_box.setCurrentIndex( index ); } } @@ -1482,11 +1489,11 @@ void creator::spell_window::populate_fields() min_field_intensity_box.setValue( sp_t.min_field_intensity ); max_field_intensity_box.setValue( sp_t.max_field_intensity ); field_intensity_variance_box.setValue( sp_t.field_intensity_variance ); - + for( int row = 0; row < affected_bps_box.count(); row++ ) { - QListWidgetItem* editItem = affected_bps_box.item( row ); + QListWidgetItem *editItem = affected_bps_box.item( row ); bodypart_str_id bpid = bodypart_str_id( editItem->text().toStdString() ); if( sp_t.affected_bps.test( bpid ) ) { editItem->setCheckState( Qt::Checked ); @@ -1508,9 +1515,9 @@ void creator::spell_window::populate_fields() sound_ambient_box.setCheckState( Qt::Checked ); } - + QStringList mon_ids; - for( const mtype_id& mon_id : sp_t.targeted_monster_ids ) { + for( const mtype_id &mon_id : sp_t.targeted_monster_ids ) { mon_ids.append( mon_id->id.c_str() ); } targeted_monster_ids_box.set_included( mon_ids ); diff --git a/src/monster.cpp b/src/monster.cpp index 331094157ba4e..cc6f2dcd943ec 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -3293,6 +3293,9 @@ void monster::set_horde_attraction( monster_horde_attraction mha ) bool monster::will_join_horde( int size ) { const monster_horde_attraction mha = get_horde_attraction(); + if( this->has_flag( MF_IMMOBILE ) ) { + return false; //immobile monsters should never join a horde. + } if( mha == MHA_NEVER ) { return false; }