From bc8811530ff074de6ef55241c2798b09518a769b Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Fri, 6 May 2022 16:49:37 +0200 Subject: [PATCH] nilrider:: saving/viewing goals --- rogueviz/nilrider/level.cpp | 3 +++ rogueviz/nilrider/nilrider.cpp | 26 +++++++++++++++++++++++--- rogueviz/nilrider/nilrider.h | 2 ++ rogueviz/nilrider/save.cpp | 27 ++++++++++++++++++++++++++- rogueviz/nilrider/solver.cpp | 1 + rogueviz/nilrider/timestamp.cpp | 11 ++++++++--- 6 files changed, 63 insertions(+), 7 deletions(-) diff --git a/rogueviz/nilrider/level.cpp b/rogueviz/nilrider/level.cpp index 0a055f85..14359f72 100644 --- a/rogueviz/nilrider/level.cpp +++ b/rogueviz/nilrider/level.cpp @@ -110,6 +110,9 @@ void level::init() { /* start facing slightly to the right from the slope */ for(auto b: {true, false}) while(true) { auto c = start; + /* no treasures are known, which confuses goals */ + dynamicval lop1(loaded_or_planned, true); + dynamicval lop2(planning_mode, false); if(c.tick(this) == b) break; start.heading_angle -= 1 * degree; } diff --git a/rogueviz/nilrider/nilrider.cpp b/rogueviz/nilrider/nilrider.cpp index 89136d53..65ff146e 100644 --- a/rogueviz/nilrider/nilrider.cpp +++ b/rogueviz/nilrider/nilrider.cpp @@ -275,9 +275,29 @@ void pick_game() { dialog::init(XLAT("how do you want to play?"), 0xC0C0FFFF, 150, 100); dialog::addSelItem("selected track", curlev->name, 't'); dialog::add_action_push(pick_level); - dialog::addInfo(curlev->longdesc); + dialog::addBreak(50); + dialog::addHelp(curlev->longdesc); dialog::addBreak(100); add_edit(planning_mode); + + int gid = 0; + for(auto& g: curlev->goals) { + dialog::addBreak(50); + auto man = curlev->records[0][gid]; + auto plan = curlev->records[1][gid]; + if(man && plan) + dialog::addInfo("manual: " + format_timer(man) + " planning: " + format_timer(plan), g.color); + else if(man) + dialog::addInfo("manual: " + format_timer(man), g.color); + else if(plan) + dialog::addInfo("planning: " + format_timer(plan), g.color); + else + dialog::addInfo("goal not obtained:", g.color); + dialog::addBreak(50); + dialog::addHelp(g.desc); + gid++; + } + dialog::addBreak(100); dialog::addBack(); dialog::display(); @@ -425,10 +445,10 @@ void main_menu() { dialog::add_action(pop_and_push_replays); } - dialog::addItem("change track or game settings", 't'); + dialog::addItem("track / mode / goals", 't'); dialog::add_action_push(pick_game); - dialog::addItem("change other settings", 'o'); + dialog::addItem("change settings", 'o'); dialog::add_action_push(settings); dialog::addItem("quit", 'q'); diff --git a/rogueviz/nilrider/nilrider.h b/rogueviz/nilrider/nilrider.h index a562d119..dd68da4b 100644 --- a/rogueviz/nilrider/nilrider.h +++ b/rogueviz/nilrider/nilrider.h @@ -202,4 +202,6 @@ hyperpoint sym_to_heis(hyperpoint H); extern int reversals; extern bool loaded_or_planned; extern bool planning_mode; + +void save(); } diff --git a/rogueviz/nilrider/save.cpp b/rogueviz/nilrider/save.cpp index b151fb4b..51fb2550 100644 --- a/rogueviz/nilrider/save.cpp +++ b/rogueviz/nilrider/save.cpp @@ -14,6 +14,17 @@ void save() { println(hlog, "save called"); fhstream f("nilrider.save", "wt"); println(f, "NilRider version ", ver); + for(auto l: all_levels) { + for(int i: {0,1}) { + int qg = isize(l->records[i]); + for(int g=0; grecords[i][g]) { + println(f, "*RECORD"); + println(f, l->name); + println(f, format("%d %d %f", i, g, l->records[i][g])); + } + } + } for(auto l: all_levels) { for(auto& p: l->manual_replays) { println(f, "*MANUAL"); @@ -71,7 +82,21 @@ void load() { if(l) l->plan_replays.emplace_back(plan_replay{name, std::move(plan)}); continue; } - println(hlog, "error: unknown content ", s); + if(s == "*RECORD") { + string lev = scanline_noblank(f); + int i = scan(f); + int g = scan(f); + ld t = scan(f); + auto l = level_by_name(lev); + if(l) { + int qg = isize(l->goals); + if(i < 0 || i > 1) println(hlog, "error: wrong number as i"); + if(g < 0 || g >= qg) println(hlog, "error: wrong goal index"); + l->records[i].resize(qg, 0); + l->records[i][g] = t; + } + println(hlog, "error: unknown content ", s); + } } } diff --git a/rogueviz/nilrider/solver.cpp b/rogueviz/nilrider/solver.cpp index 3e8f2221..4b75c862 100644 --- a/rogueviz/nilrider/solver.cpp +++ b/rogueviz/nilrider/solver.cpp @@ -68,6 +68,7 @@ void level::solve() { ts.where = point0; ts.collected_triangles = v.collected; ts.timer = 0; + loaded_or_planned = true; ts.collect(this); checkerparam p {&ts, this, 0}; auto res = goals[goal_id].check(p); diff --git a/rogueviz/nilrider/timestamp.cpp b/rogueviz/nilrider/timestamp.cpp index b07e2721..fab9ba36 100644 --- a/rogueviz/nilrider/timestamp.cpp +++ b/rogueviz/nilrider/timestamp.cpp @@ -98,9 +98,14 @@ bool timestamp::collect(level *lev) { else if(res == grSuccess) { goals |= Flag(gid); lev->current_score[gid] = timer; - auto &res = lev->records[planning_mode][gid]; - if(res == 0 || timer < res) - res = timer; + if(planning_mode || !loaded_or_planned) { + auto &res = lev->records[planning_mode][gid]; + if(res == 0 || timer < res) { + res = timer; + println(hlog, "saved -- success on goal ", gid, " in time ", timer); + save(); + } + } } gid++; }