mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-04-03 09:17:02 +00:00
load/save/place dice in the map editor
This commit is contained in:
parent
8f563f5deb
commit
50a9c78343
20
complex2.cpp
20
complex2.cpp
@ -955,6 +955,8 @@ EX namespace dice {
|
||||
{3,5,4,9,1}, {0,9,6,7,3}, {11,10,5,3,7}, {0,1,7,2,5}, {0,5,10,8,9}, {0,3,2,10,4},
|
||||
{11,7,1,9,8}, {11,2,3,1,6}, {11,6,9,4,10}, {0,4,8,6,1}, {11,8,4,5,2}, {8,10,2,7,6}
|
||||
});
|
||||
|
||||
vector<die_structure*> die_list = {&d4, &d6, &d8, &d12, &d20};
|
||||
|
||||
#if HDR
|
||||
struct die_data {
|
||||
@ -971,6 +973,14 @@ EX namespace dice {
|
||||
return 0;
|
||||
}
|
||||
|
||||
EX die_structure *get_by_id(unsigned i) { return die_list[i % isize(die_list)]; }
|
||||
EX int get_die_id(die_structure *ds) {
|
||||
for(int i=0; i<isize(die_list); i++)
|
||||
if(die_list[i] == ds)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
EX map<cell*, die_data> data;
|
||||
|
||||
EX void generate_specific(cell *c, die_structure *ds, int min_hardness, int max_hardness) {
|
||||
@ -1012,6 +1022,16 @@ EX namespace dice {
|
||||
auto& dw = dd.which;
|
||||
return can_roll(dw->facesides, dd.dir, mi);
|
||||
}
|
||||
|
||||
EX bool generate_random(cell *c) {
|
||||
vector<die_structure*> ds;
|
||||
for(die_structure* pds: {&d4, &d6, &d8, &d12, &d20})
|
||||
if(c->type % pds->facesides == 0)
|
||||
ds.push_back(pds);
|
||||
if(ds.empty()) return false;
|
||||
generate_specific(c, hrand_elt(ds), 0, 99);
|
||||
return true;
|
||||
}
|
||||
|
||||
EX void generate_full(cell *c, int hard) {
|
||||
int dp = die_possible(c);
|
||||
|
@ -672,6 +672,12 @@ EX namespace mapstream {
|
||||
if(c->monst == moTortoise)
|
||||
f.write(tortoise::emap[c] = tortoise::getb(c));
|
||||
f.write_char(c->wall);
|
||||
if(dice::on(c)) {
|
||||
auto& dat = dice::data[c];
|
||||
f.write_char(dice::get_die_id(dat.which));
|
||||
f.write_char(dat.val);
|
||||
f.write_char(dat.dir);
|
||||
}
|
||||
// f.write_char(c->barleft);
|
||||
// f.write_char(c->barright);
|
||||
f.write_char(c->item);
|
||||
@ -822,6 +828,12 @@ EX namespace mapstream {
|
||||
if(c->monst == moTortoise && f.vernum >= 11001)
|
||||
f.read(tortoise::emap[c]);
|
||||
c->wall = (eWall) f.read_char();
|
||||
if(dice::on(c)) {
|
||||
auto& dat = dice::data[c];
|
||||
dat.which = dice::get_by_id(f.read_char());
|
||||
dat.val = f.read_char();
|
||||
dat.dir = fixspin(rspin, f.read_char(), c->type, f.vernum);
|
||||
}
|
||||
// c->barleft = (eLand) f.read_char();
|
||||
// c->barright = (eLand) f.read_char();
|
||||
c->item = (eItem) f.read_char();
|
||||
@ -1217,6 +1229,10 @@ EX namespace mapeditor {
|
||||
for(int i=0; i<100; i++) c1 = c1->cmove(hrand(c1->type));
|
||||
tortoise::emap[c] = tortoise::getRandomBits();
|
||||
}
|
||||
|
||||
if(isDie(c->monst)) {
|
||||
if(!dice::generate_random(c)) c->monst = moNone;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
@ -1258,6 +1274,11 @@ EX namespace mapeditor {
|
||||
c->wparam = paintstatueid;
|
||||
c->mondir = cdir;
|
||||
}
|
||||
|
||||
if(isDie(c->wall)) {
|
||||
if(!dice::generate_random(c)) c->wall = waNone;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
@ -1283,6 +1304,7 @@ EX namespace mapeditor {
|
||||
c->wparam = copywhat->wparam;
|
||||
c->hitpoints = copywhat->hitpoints;
|
||||
c->stuntime = copywhat->stuntime;
|
||||
if(dice::on(c)) dice::data[c] = dice::data[copywhat];
|
||||
if(copywhat->mondir == NODIR) c->mondir = NODIR;
|
||||
else c->mondir = gmod((where.first.mirrored == where.second.mirrored ? 1 : -1) * (copywhat->mondir - where.second.spin) + cdir, c->type);
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user