1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2026-05-11 09:32:05 +00:00

ru:: random potion powers are now restricted to rooms

This commit is contained in:
Zeno Rogue
2026-03-29 16:01:37 +02:00
parent 925cc5ada1
commit 09ed49cf80
6 changed files with 34 additions and 1 deletions
+5
View File
@@ -12,8 +12,11 @@ struct data {
struct power *p;
struct randeff *re;
rev mode;
flagtype flags;
};
flagtype DO_NOT_DRINK = 1;
using powerfun = hr::function<void(data&)>;
struct randeff {
@@ -24,6 +27,7 @@ struct randeff {
power *which_weapon;
int qty, a, b, c, d;
powerfun act;
powerfun unact;
randeff (string name, string desc, string effect, powerfun act);
void hs(struct stater& s);
};
@@ -44,6 +48,7 @@ struct power {
int flags;
int random_value;
vector<struct randeff*> randeffs;
set<struct room*> active_in_rooms;
void init();
vector<struct weaponmod> mods;
hr::function<void(data&)> act, paused_act, dead_act;
+7 -1
View File
@@ -236,8 +236,13 @@ power& power::be_potion() {
}
void random_potion_act(data& d) {
if(d.p->qty_filled == d.p->qty_owned) d.p->flags &=~ ACTIVE;
if(d.p->qty_filled == d.p->qty_owned) d.p->active_in_rooms.clear();
d.p->flags &=~ ACTIVE;
if(d.p->active_in_rooms.count(current_room)) d.p->flags |= ACTIVE;
if(d.keystate == 1 && !(d.p->flags & ACTIVE)) {
d.flags &=~ DO_NOT_DRINK;
for(auto& e: d.p->randeffs) e->unact(d);
if(d.flags & DO_NOT_DRINK) return;
if(d.p->qty_filled == 0) {
addMessage("You have no more " + d.p->get_name());
return;
@@ -250,6 +255,7 @@ void random_potion_act(data& d) {
d.re = e; d.mode = rev::start;
e->act(d);
}
d.p->active_in_rooms.insert(current_room);
d.p->flags |= (ACTIVE | PARTIAL | IDENTIFIED);
d.p->qty_filled--;
}
+9
View File
@@ -7,6 +7,7 @@ randeff::randeff (string name, string desc, string effect, powerfun act)
id = unspace(name);
if(!all_effects) all_effects = new map<string, randeff*>;
(*all_effects)[id] = this;
unact = [] (data&d) {};
}
randeff inc_str("Strength", "Increases your Strength by 50%.", "You feel stronger!", [] (data &d) { m.next.stats[stat::str] += m.current.stats[stat::str] / 3; });
@@ -263,6 +264,14 @@ vector<power*> all_weapons() {
return res;
}
void gen_randeffs() {
powerfun unmorph = [] (data& d) {
if(m.morphed) { m.handle_morph(nullptr); if(!m.morphed) d.flags |= DO_NOT_DRINK; }
};
morph_cat.unact = unmorph;
morph_capy.unact = unmorph;
}
void assign_potion_powers() {
vector<randeff*> random_powers = { &inc_str, &inc_dex, &inc_con, &inc_wis, &dec_str, &dec_dex, &dec_con, &dec_wis, &hallux, &confux };
hrandom_shuffle(random_powers);
+5
View File
@@ -12,6 +12,11 @@ room *find_room_by_name(string s) {
throw hr_name_error("find_room");
}
room *may_find_room_by_id(string s) {
for(auto& [c,r]: rooms) if(r.id == s) return &r;
return nullptr;
}
entity* find_entity_by_id(string s) {
auto e = entity_by_id[s];
if(!e) throw hr_name_error("find_entity");
+1
View File
@@ -409,6 +409,7 @@ void enable() {
set_sval();
init_scales();
gen_powers();
gen_randeffs();
shuffle_all();
hyperpoint aleft = deparabolic13(to_hyper(l_margin_at, yctr));
+7
View File
@@ -49,6 +49,7 @@ void save_as(string fname) {
// list current powers
for(auto& p: powers) {
save_via_stater(f, p, "POWER", isize(p.randeffs));
for(auto& r: p.active_in_rooms) println(f, "ACTIVE-IN ", r->id);
for(auto& r: p.randeffs) save_via_stater(f, *r, "EFFECT", true);
}
@@ -212,6 +213,7 @@ void load_from(string fname) {
current_power = nullptr;
try {
current_power = &find_power_by_id(param);
current_power->active_in_rooms.clear();
load_hs(f, *current_power);
current_power->randeffs = {};
}
@@ -219,6 +221,11 @@ void load_from(string fname) {
println(hlog, "warning: unknown power: ", param);
}
}
else if(cap == "ACTIVE-IN") {
auto r = may_find_room_by_id(param);
if(!r) println(hlog, "warning: active in a room that does not exist");
current_power->active_in_rooms.insert(r);
}
else if(cap == "EFFECT") {
if(!all_effects->count(param)) {
println(hlog, "warning: unknown effect: ", param);