From 566c466b665c802a5f1b2f05f68fe2cbf62f8dd3 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Tue, 17 Jul 2018 14:28:49 +0200 Subject: [PATCH] loading/saving irregular maps to config and log (and recreate automatically)H --- config.cpp | 8 ++++ floorshapes.cpp | 12 ++--- hyper.h | 6 +++ init.cpp | 1 + irregular.cpp | 116 +++++++++++++++++++++++++++++------------------- system.cpp | 5 ++- 6 files changed, 95 insertions(+), 53 deletions(-) diff --git a/config.cpp b/config.cpp index 2af11b6f..115c0b38 100644 --- a/config.cpp +++ b/config.cpp @@ -262,6 +262,14 @@ void initConfig() { addsaver(nohud, "no-hud", false); addsaver(nofps, "no-fps", false); + addsaver(irr::on, "irregular", false); + addsaver(irr::density, "irregular-density", 6); + addsaver(irr::cellcount, "irregular-cellcount", 150); + addsaver(irr::quality, "irregular-quality", .2); + addsaver(irr::place_attempts, "irregular-place", 10); + addsaver(irr::rearrange_max_attempts, "irregular-rearrange-max", 50); + addsaver(irr::rearrange_less, "irregular-rearrangeless", 10); + #if CAP_SHMUP shmup::initConfig(); #endif diff --git a/floorshapes.cpp b/floorshapes.cpp index a01f0c84..4cff8b1a 100644 --- a/floorshapes.cpp +++ b/floorshapes.cpp @@ -513,9 +513,9 @@ namespace irr { /* if(siid == 0) for(auto& ma: m.v) ma.first = ma.first * pispin; */ - fsh.b.resize(irr::sc); + fsh.b.resize(irr::cellcount); - for(int id=0; id cornerlist; @@ -580,7 +580,7 @@ namespace irr { for(int k=0; k t + 250) { make_cells_of_heptagon(); status[0] = its(isize(cells)) + " cells"; return false; } cellinfo s; s.patterndir = -1; ld bestval = 0; - for(int j=0; j<10; j++) { + for(int j=0; jtype); @@ -155,7 +159,7 @@ bool step(int delta) { int stats[16]; for(int k=0; k<16; k++) stats[k] = 0; - for(int i=0; i 0) status[1] = XLAT("bad cells: %1", its(errors)); else status[1] = " "; if(toobig > 0) status[2] = XLAT("too many edges: %1", its(toobig)); else status[2] = " "; - if(isize(cells) < sc*3/4) runlevel = 0; - else if(isize(cells) < sc) runlevel = 1; - else { rearrange_attempts = 20; runlevel++; } + if(isize(cells) < cellcount*3/4) runlevel = 0; + else if(isize(cells) < cellcount) runlevel = 1; + else { rearrange_index = 0; runlevel++; } break; } @@ -254,23 +258,29 @@ bool step(int delta) { ld minedge = median * quality; status[3] = XLAT("median edge: %1 minimum: %2", fts4(median), fts4(edgelens[0])); if(edgelens[0] < minedge) { + if(rearrange_index >= rearrange_max_attempts) { + runlevel = 0; break; + } int tooshort = 0; for(int i=0; iallcells()) * density + .5); - printf("density = %lf sc = %d\n", double(density), sc); - if(sc > s) runlevel = 1; - if(sc < s) runlevel = 0; + cellcount = int(isize(currentmap->allcells()) * density + .5); + printf("density = %lf cellcount = %d\n", double(density), cellcount); + if(cellcount > s) runlevel = 1; + if(cellcount < s) runlevel = 0; }; }); dialog::addSelItem(XLAT("min edge to median"), fts(quality), 'q'); @@ -506,27 +538,9 @@ void show_gridmaker() { dialog::addInfo(status[i]); dialog::addBreak(100); dialog::addSelItem(XLAT("activate"), XLAT(runlevel == 10 ? "ready" : "wait..."), 'f'); - if(runlevel == 10) dialog::add_action([] { - popScreen(); - for(hrmap *& hm : allmaps) if(hm == base) hm = NULL; - stop_game(); - geometry = orig_geometry; - irr::on = true; - nonbitrunc = true; - gp::on = false; - need_reset_geometry = true; - gridmaking = false; - start_game(); - }); + if(runlevel == 10) dialog::add_action(start_game_on_created_map); dialog::addItem(XLAT("cancel"), 'c'); - dialog::add_action([] { - gridmaking = false; - stop_game(); - geometry = orig_geometry; - need_reset_geometry = true; - start_game(); - popScreen(); - }); + dialog::add_action(cancel_map_creation); dialog::display(); keyhandler = [] (int sym, int uni) { dialog::handleNavigation(sym, uni); @@ -554,13 +568,23 @@ void visual_creator() { gp::on = false; need_reset_geometry = true; start_game(); + if(base) delete base; base = currentmap; drawthemap(); - sc = int(isize(base->allcells()) * density + .5); + cellcount = int(isize(base->allcells()) * density + .5); pushScreen(show_gridmaker); runlevel = 0; gridmaking = true; } + +void auto_creator() { + int cc = cellcount; + visual_creator(); + cellcount = cc; density = cc / isize(base->allcells()); + printf("Creating the irregular map automatically...\n"); + while(runlevel < 10) step(1000); + start_game_on_created_map(); + } int readArgs() { using namespace arg; @@ -577,9 +601,9 @@ int readArgs() { } unsigned char density_code() { - if(sc < 128) return sc; + if(cellcount < 128) return cellcount; else { - int t = 127, a = sc; + int t = 127, a = cellcount; while(a > 127) a = a * 9/10, t++; return t; } diff --git a/system.cpp b/system.cpp index 4384da29..9c7d72a6 100644 --- a/system.cpp +++ b/system.cpp @@ -300,7 +300,7 @@ bool havesave = true; #if CAP_SAVE #define MAXBOX 500 -#define POSSCORE 344 // update this when new boxes are added! +#define POSSCORE 346 // update this when new boxes are added! struct score { string ver; @@ -693,6 +693,9 @@ void applyBoxes() { applyBoxBool(gp::on); applyBox(gp::param.first); applyBox(gp::param.second); + + applyBoxBool(irr::on); + applyBox(irr::cellcount); if(POSSCORE != boxid) printf("ERROR: %d boxes\n", boxid); }