1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-06-27 15:32:53 +00:00

ru:: cheat feature for quicker testing

This commit is contained in:
Zeno Rogue 2025-05-02 22:23:27 +02:00
parent a3c42c89be
commit 4ff77aa64e
3 changed files with 45 additions and 0 deletions

4
rogueviz/ru/cheat.txt Normal file
View File

@ -0,0 +1,4 @@
START Central Cavern
ITEM dagger
GAIN 5 3
POS 320 100

View File

@ -407,6 +407,7 @@ void add_platf_hooks() {
}
auto chk = arg::add3("-ru", enable)
+ arg::add3("-ru-cheat", [] { arg::shift(); load_cheat(arg::args()); })
+ addHook(mapstream::hooks_loadmap, 100, [] (hstream& f, int id) {
if(id == 67) {
println(hlog, "loading platformer");

View File

@ -160,5 +160,45 @@ void load_map(string fname) {
}
}
void load_cheat(string fname) {
fhstream f(fname, "r");
auto power_edited = &powers[0];
while(!feof(f.f)) {
string s = scanline_noblank(f);
auto pos = s.find(" ");
if(pos != string::npos) {
string cap = s.substr(0, pos);
string param = s.substr(pos+1);
if(cap == "START") {
for(auto& [c,r]: rooms) if(r.roomname == param) current_room = &r;
}
else if(cap == "POS") {
sscanf(param.c_str(), "%lf%lf", &m.where_x, &m.where_y);
}
else if(cap == "ITEM") {
bool found = false;
for(int i=0; i<isize(powers); i++) if(powers[i].name == param) found = true, power_edited = &powers[i];
if(!found) println(hlog, "cheat item not found: ", param);
}
else if(cap == "GAIN") {
int a, b;
sscanf(param.c_str(), "%d%d", &a, &b);
power_edited->qty_owned += a;
power_edited->qty_filled += b;
println(hlog, "gain ", power_edited->name, " qty ", tie(a,b));
}
else println(hlog, "unrecognized cheat: ", s);
}
else if(s == "IDENTIFY") {
power_edited->flags |= IDENTIFIED;
}
else if(s == "ACTIVATE") {
power_edited->flags |= ACTIVE;
}
else if(s == "") {}
else println(hlog, "unrecognized cheat: ", s);
}
}
}