1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-06-27 07:22:51 +00:00

ru:: some work on potions

This commit is contained in:
Zeno Rogue 2025-05-05 11:50:52 +02:00
parent 69b5950792
commit 3790269e79
2 changed files with 65 additions and 6 deletions

View File

@ -23,6 +23,7 @@ struct power {
int qty_filled; int qty_filled;
int qty_owned; int qty_owned;
flagtype flags; flagtype flags;
int random_flavor;
void init(); void init();
hr::function<void(data&)> act, paused_act; hr::function<void(data&)> act, paused_act;
hr::function<string()> get_name; hr::function<string()> get_name;
@ -39,6 +40,7 @@ struct power {
power& identified_name(string, string); power& identified_name(string, string);
power& be_wearable(string wear_effect, string remove_effect); power& be_wearable(string wear_effect, string remove_effect);
power& be_jewelry(string jtype, string desc); power& be_jewelry(string jtype, string desc);
power& be_potion();
}; };
extern vector<power> powers; extern vector<power> powers;

View File

@ -2,6 +2,7 @@ namespace rogue_unlike {
flagtype IDENTIFIED = Flag(1); flagtype IDENTIFIED = Flag(1);
flagtype ACTIVE = Flag(2); flagtype ACTIVE = Flag(2);
flagtype PARTIAL = Flag(4);
data fakedata; data fakedata;
@ -36,6 +37,7 @@ power& power::be_resource(string s) {
} }
using flavor = pair<string, color_t>; using flavor = pair<string, color_t>;
int next_potion, next_jewelry;
vector<flavor> jewelry_colors = { vector<flavor> jewelry_colors = {
{"steel", 0xA0A0C0FF}, {"steel", 0xA0A0C0FF},
@ -45,7 +47,15 @@ vector<flavor> jewelry_colors = {
{"emerald", 0x60C060FF}, {"emerald", 0x60C060FF},
}; };
int next_jewelry; vector<flavor> potion_colors = {
{"bubbling", 0xC0C0C0FF},
{"golden", 0xFFD500FF},
{"red", 0xC00000FF},
{"blue", 0x0000C0FF},
{"green", 0x00C000FF},
{"white", 0xFFFFFFFF},
{"black", 0x303030FF},
};
power& power::be_jewelry(string jtype, string xdesc) { power& power::be_jewelry(string jtype, string xdesc) {
int nj = next_jewelry++; int nj = next_jewelry++;
@ -83,6 +93,27 @@ power& power::be_wearable(string wear_effect, string remove_effect) {
return self; return self;
} }
power& power::be_potion() {
int np = next_potion++;
picked_up = [this] (int x) { qty_owned += x; qty_filled = max(qty_filled, x); };
get_color = [np] { return potion_colors[np].second; };
refill = [this] { qty_filled = qty_owned; };
reshuffle = [this] { random_flavor = rand() % 5040; flags &=~ IDENTIFIED; };
get_name = [np, this] {
string fname = potion_colors[np].first + " potion";
if(flags & (PARTIAL | IDENTIFIED)) fname = fname + " of " + name;
fname += " (" + its(qty_filled) + "/" + its(qty_owned) + ")";
return fname;
};
auto gd = get_desc;
get_desc = [this, gd] () -> string {
if(!(flags & (PARTIAL | IDENTIFIED)))
return "You will need to drink this potion to identify it.";
else return gd();
};
return self;
}
vector<power> powers; vector<power> powers;
void power::init() { void power::init() {
@ -116,14 +147,14 @@ power& gen_power(int key, string name, string desc, string glyph, color_t color,
void gen_powers() { void gen_powers() {
powers.reserve(100); powers.reserve(100);
gen_power('1', "Potion of Extra Life", gen_power('1', "Extra Life",
"You are really proud of this potion, which, after you die, will let you return to the moment of time when you drank it. " "You are really proud of this potion, which, after you die, will let you return to the moment of time when you drank it. "
"Unfortunately it still requires an ingredient found only in the magical fountains of the Dungeons of Alchemy.\n\n" "Unfortunately it still requires an ingredient found only in the magical fountains of the Dungeons of Alchemy.\n\n"
"You can only drink this potion when at a magical fountain. To protect yourself from dying permanently, it is drank " "You can only drink this potion when at a magical fountain. To protect yourself from dying permanently, when you drink it, "
"automatically whenever you are at a magical fountain.", "you drink it automatically whenever you are at a magical fountain.",
"!", 0xFFFF00FF, "!", 0xFFFF00FF,
[] (data& d) { } [] (data& d) { d.p->flags |= IDENTIFIED; }
).is_starting(), ).is_starting().be_potion(),
gen_power('d', "move right", gen_power('d', "move right",
"A special power of human beings, and most other animals, that they earn early in their life.", "A special power of human beings, and most other animals, that they earn early in their life.",
@ -300,6 +331,30 @@ void gen_powers() {
).be_jewelry("ring", "You need to wear this ring to know what it does.") ).be_jewelry("ring", "You need to wear this ring to know what it does.")
.be_wearable("You put the % on your finger. You feel better with bows!", "You remove the %. You feel worse with bows..."), .be_wearable("You put the % on your finger. You feel better with bows!", "You remove the %. You feel worse with bows..."),
gen_power('2', "health",
"This will cure your wounds, in some way.",
"!", 0xFFFF00FF,
[] (data& d) { if(d.keystate == 1) d.p->flags |= (PARTIAL | IDENTIFIED); }
).be_potion(),
gen_power('3', "reach",
"This will let you reach heights, in some way.",
"!", 0xFFFF00FF,
[] (data& d) { if(d.keystate == 1) d.p->flags |= (PARTIAL | IDENTIFIED); }
).be_potion(),
gen_power('4', "fire",
"This will let you produce fire, in some way.",
"!", 0xFFFF00FF,
[] (data& d) { if(d.keystate == 1) d.p->flags |= (PARTIAL | IDENTIFIED); }
).be_potion(),
gen_power('5', "polymorph",
"This will let you change into a small creature.",
"!", 0xFFFF00FF,
[] (data& d) { if(d.keystate == 1) d.p->flags |= (PARTIAL | IDENTIFIED); }
).be_potion(),
gen_power('g', "gold", gen_power('g', "gold",
"For some weird reason, people love gold, and they will give you anything if you give them enough gold.\n\n" "For some weird reason, people love gold, and they will give you anything if you give them enough gold.\n\n"
"This can be used to buy things in shops. " "This can be used to buy things in shops. "
@ -367,6 +422,8 @@ void draw_inventory() {
void shuffle_all() { void shuffle_all() {
auto& jc = jewelry_colors; auto& jc = jewelry_colors;
for(int i=1; i<isize(jc); i++) swap(jc[i], jc[rand() % (i+1)]); for(int i=1; i<isize(jc); i++) swap(jc[i], jc[rand() % (i+1)]);
auto& pc = potion_colors;
for(int i=1; i<isize(pc); i++) swap(pc[i], pc[rand() % (i+1)]);
for(auto& p: powers) p.reshuffle(); for(auto& p: powers) p.reshuffle();
} }