From 651b851fdd2a36958e09a66cb2877c66cf160a5e Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Tue, 18 Jul 2023 10:19:42 -0400 Subject: better warrior placement, including handling the case where they don't fit --- bench/bench_window.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'bench') diff --git a/bench/bench_window.cpp b/bench/bench_window.cpp index 70cbbbf..99d7926 100644 --- a/bench/bench_window.cpp +++ b/bench/bench_window.cpp @@ -1,3 +1,4 @@ +#include #include #include "bench_window.hpp" @@ -193,7 +194,22 @@ void bench_window::on_click_new_round() { .bnumber = 0 }); - lib94::init_round(warriors.data(), warriors.size()); + if (!lib94::init_round(warriors.data(), warriors.size())) { + Gtk::MessageDialog *md = new Gtk::MessageDialog("warriors do not fit in core; removing last warrior"); + md->set_transient_for(*this); + md->set_modal(); + md->signal_response().connect([md](int) {delete md;}); + md->show(); + + //is this safe? + delete warriors.back(); + warriors.pop_back(); + if (warriors.size() == 0) { + update_ui(); + return; + } + assert(lib94::init_round(warriors.data(), warriors.size())); + } core.mut.lock(); core.age_scale = std::pow(2.0 / 3.0, 1.0 / (float)warriors.size()); -- cgit v1.2.3