mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-11-23 21:07:17 +00:00
nilrider:: basic save functionality (no load though)
This commit is contained in:
parent
3072a998ba
commit
62331b43f1
@ -5,6 +5,7 @@
|
|||||||
#include "level.cpp"
|
#include "level.cpp"
|
||||||
#include "planning.cpp"
|
#include "planning.cpp"
|
||||||
#include "solver.cpp"
|
#include "solver.cpp"
|
||||||
|
#include "save.cpp"
|
||||||
|
|
||||||
namespace nilrider {
|
namespace nilrider {
|
||||||
|
|
||||||
@ -254,13 +255,19 @@ void main_menu() {
|
|||||||
dialog::addItem("view the replay", 'v');
|
dialog::addItem("view the replay", 'v');
|
||||||
dialog::add_action(toggle_replay);
|
dialog::add_action(toggle_replay);
|
||||||
|
|
||||||
dialog::addItem("save the replay", 'e');
|
dialog::addItem("save the replay", 's');
|
||||||
dialog::add_action([] {
|
dialog::add_action([] {
|
||||||
|
vector<int> ang;
|
||||||
|
for(auto& h: curlev->history) ang.push_back(heading_to_int(h.heading_angle));
|
||||||
|
curlev->manual_replays.emplace_back(manual_replay{new_replay_name(), std::move(ang)});
|
||||||
|
save();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dialog::addItem("save this plan", 's');
|
dialog::addItem("save this plan", 's');
|
||||||
dialog::add_action([] {
|
dialog::add_action([] {
|
||||||
|
curlev->plan_replays.emplace_back(plan_replay{new_replay_name(), curlev->plan});
|
||||||
|
save();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,8 @@ struct planpoint {
|
|||||||
planpoint(hyperpoint a, hyperpoint v): at(a), vel(v) {};
|
planpoint(hyperpoint a, hyperpoint v): at(a), vel(v) {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using plan_t = vector<planpoint>;
|
||||||
|
|
||||||
constexpr flagtype nrlPolar = Flag(1);
|
constexpr flagtype nrlPolar = Flag(1);
|
||||||
|
|
||||||
struct statue {
|
struct statue {
|
||||||
@ -47,6 +49,16 @@ struct triangledata {
|
|||||||
array<color_t, 7> colors;
|
array<color_t, 7> colors;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct manual_replay {
|
||||||
|
string name;
|
||||||
|
vector<int> headings;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct plan_replay {
|
||||||
|
string name;
|
||||||
|
plan_t plan;
|
||||||
|
};
|
||||||
|
|
||||||
struct level {
|
struct level {
|
||||||
string name;
|
string name;
|
||||||
char hotkey;
|
char hotkey;
|
||||||
@ -94,8 +106,11 @@ struct level {
|
|||||||
|
|
||||||
vector<timestamp> history;
|
vector<timestamp> history;
|
||||||
|
|
||||||
|
vector<manual_replay> manual_replays;
|
||||||
|
vector<plan_replay> plan_replays;
|
||||||
|
|
||||||
/** plan for the planning mode */
|
/** plan for the planning mode */
|
||||||
vector<planpoint> plan;
|
plan_t plan;
|
||||||
void init_plan();
|
void init_plan();
|
||||||
bool simulate();
|
bool simulate();
|
||||||
void draw_planning_screen();
|
void draw_planning_screen();
|
||||||
|
37
rogueviz/nilrider/save.cpp
Normal file
37
rogueviz/nilrider/save.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
namespace nilrider {
|
||||||
|
|
||||||
|
const string ver = "0.1";
|
||||||
|
|
||||||
|
string new_replay_name() {
|
||||||
|
time_t timer;
|
||||||
|
timer = time(NULL);
|
||||||
|
char timebuf[128];
|
||||||
|
strftime(timebuf, 128, "%y%m%d-%H%M%S", localtime(&timer));
|
||||||
|
return timebuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void save() {
|
||||||
|
println(hlog, "save called");
|
||||||
|
fhstream f("nilrider.save", "wt");
|
||||||
|
println(f, "version ", ver);
|
||||||
|
for(auto l: all_levels) {
|
||||||
|
for(auto& p: l->manual_replays) {
|
||||||
|
println(f, "*MANUAL");
|
||||||
|
println(f, l->name);
|
||||||
|
println(f, p.name);
|
||||||
|
println(f, isize(p.headings));
|
||||||
|
for(auto t: p.headings) println(f, t);
|
||||||
|
println(f);
|
||||||
|
}
|
||||||
|
for(auto& p: l->plan_replays) {
|
||||||
|
println(f, "*PLANNING");
|
||||||
|
println(f, l->name);
|
||||||
|
println(f, p.name);
|
||||||
|
println(f, isize(p.plan));
|
||||||
|
for(auto t: p.plan) println(f, format("%.6f %.6f %.6f %.6f", t.at[0], t.at[1], t.vel[0], t.vel[1]));
|
||||||
|
println(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user