mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-12-27 18:40:35 +00:00
commit
9941d602f6
63
graph.cpp
63
graph.cpp
@ -45,7 +45,23 @@ EX bool hide_player() {
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ADC(V,c) IF_KEY_EXISTS(it, current_display->all_drawn_copies, c) for(const shiftmatrix& V: it->second)
|
template<class T>
|
||||||
|
class span {
|
||||||
|
T *begin_ = nullptr;
|
||||||
|
T *end_ = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit span() = default;
|
||||||
|
explicit span(T *p, int n) : begin_(p), end_(p + n) {}
|
||||||
|
T *begin() const { return begin_; }
|
||||||
|
T *end() const { return end_; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class Map, class Key>
|
||||||
|
hr::span<const shiftmatrix> span_at(const Map& map, const Key& key) {
|
||||||
|
auto it = map.find(key);
|
||||||
|
return (it == map.end()) ? hr::span<const shiftmatrix>() : hr::span<const shiftmatrix>(it->second.data(), it->second.size());
|
||||||
|
}
|
||||||
|
|
||||||
EX hookset<bool(int sym, int uni)> hooks_handleKey;
|
EX hookset<bool(int sym, int uni)> hooks_handleKey;
|
||||||
EX hookset<bool(cell *c, const shiftmatrix& V)> hooks_drawcell;
|
EX hookset<bool(cell *c, const shiftmatrix& V)> hooks_drawcell;
|
||||||
@ -4361,7 +4377,8 @@ EX void queuecircleat1(cell *c, const shiftmatrix& V, double rad, color_t col) {
|
|||||||
|
|
||||||
EX void queuecircleat(cell *c, double rad, color_t col) {
|
EX void queuecircleat(cell *c, double rad, color_t col) {
|
||||||
if(!c) return;
|
if(!c) return;
|
||||||
ADC(V, c) queuecircleat1(c, V, rad, col);
|
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, c))
|
||||||
|
queuecircleat1(c, V, rad, col);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -4418,10 +4435,11 @@ EX void drawMarkers() {
|
|||||||
ignore(ok);
|
ignore(ok);
|
||||||
|
|
||||||
#if CAP_QUEUE
|
#if CAP_QUEUE
|
||||||
if(haveMount()) ADC(V, dragon::target) {
|
if(haveMount())
|
||||||
queuestr(V, 1, "X",
|
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, dragon::target)) {
|
||||||
gradient(0, iinf[itOrbDomination].color, -1, sintick(dragon::whichturn == turncount ? 75 : 150), 1));
|
queuestr(V, 1, "X",
|
||||||
}
|
gradient(0, iinf[itOrbDomination].color, -1, sintick(dragon::whichturn == turncount ? 75 : 150), 1));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* for(int i=0; i<12; i++) if(c->type == 5 && c->master == &dodecahedron[i])
|
/* for(int i=0; i<12; i++) if(c->type == 5 && c->master == &dodecahedron[i])
|
||||||
@ -4536,16 +4554,20 @@ EX void drawMarkers() {
|
|||||||
|
|
||||||
int adj = 1 - ((sword_angles/cwt.at->type)&1);
|
int adj = 1 - ((sword_angles/cwt.at->type)&1);
|
||||||
|
|
||||||
if(items[itOrbSword]) ADC(V, cwt.at)
|
if(items[itOrbSword])
|
||||||
queuestr(V * spin(M_PI+(-adj-2*ang)*M_PI/sword_angles) * xpush0(cgi.sword_size), vid.fsize*2, "+", iinf[itOrbSword].color);
|
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, cwt.at))
|
||||||
if(items[itOrbSword2]) ADC(V, cwt.at)
|
queuestr(V * spin(M_PI+(-adj-2*ang)*M_PI/sword_angles) * xpush0(cgi.sword_size), vid.fsize*2, "+", iinf[itOrbSword].color);
|
||||||
queuestr(V * spin((-adj-2*ang)*M_PI/sword_angles) * xpush0(-cgi.sword_size), vid.fsize*2, "+", iinf[itOrbSword2].color);
|
if(items[itOrbSword2])
|
||||||
|
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, cwt.at))
|
||||||
|
queuestr(V * spin((-adj-2*ang)*M_PI/sword_angles) * xpush0(-cgi.sword_size), vid.fsize*2, "+", iinf[itOrbSword2].color);
|
||||||
}
|
}
|
||||||
if(SWORDDIM == 3 && !shmup::on) {
|
if(SWORDDIM == 3 && !shmup::on) {
|
||||||
if(items[itOrbSword]) ADC(V, cwt.at)
|
if(items[itOrbSword])
|
||||||
queuestr(V * sword::dir[multi::cpid].T * xpush0(cgi.sword_size), vid.fsize*2, "+", iinf[itOrbSword].color);
|
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, cwt.at))
|
||||||
if(items[itOrbSword2]) ADC(V, cwt.at)
|
queuestr(V * sword::dir[multi::cpid].T * xpush0(cgi.sword_size), vid.fsize*2, "+", iinf[itOrbSword].color);
|
||||||
queuestr(V * sword::dir[multi::cpid].T * xpush0(-cgi.sword_size), vid.fsize*2, "+", iinf[itOrbSword2].color);
|
if(items[itOrbSword2])
|
||||||
|
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, cwt.at))
|
||||||
|
queuestr(V * sword::dir[multi::cpid].T * xpush0(-cgi.sword_size), vid.fsize*2, "+", iinf[itOrbSword2].color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4603,10 +4625,17 @@ void drawFlashes() {
|
|||||||
bool kill = true;
|
bool kill = true;
|
||||||
flashdata& f = flashes[k];
|
flashdata& f = flashes[k];
|
||||||
bool copies = false;
|
bool copies = false;
|
||||||
ADC(V, f.where) copies = true, draw_flash(f, V, kill);
|
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, f.where)) {
|
||||||
forCellIdEx(c2, id, f.where) if(!copies) ADC(V, c2) {
|
|
||||||
draw_flash(f, V * currentmap->iadj(f.where, id), kill);
|
|
||||||
copies = true;
|
copies = true;
|
||||||
|
draw_flash(f, V, kill);
|
||||||
|
}
|
||||||
|
forCellIdEx(c2, id, f.where) {
|
||||||
|
if(!copies) {
|
||||||
|
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, c2)) {
|
||||||
|
draw_flash(f, V * currentmap->iadj(f.where, id), kill);
|
||||||
|
copies = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(f.t > ticks - 800 && !copies) {
|
if(f.t > ticks - 800 && !copies) {
|
||||||
kill = false;
|
kill = false;
|
||||||
|
12
hyper.h
12
hyper.h
@ -575,11 +575,6 @@ typedef function<int(struct cell*)> cellfunction;
|
|||||||
#define forCellCM(ct, cf) forCellIdCM(ct,forCellCM ## __LINE__,cf)
|
#define forCellCM(ct, cf) forCellIdCM(ct,forCellCM ## __LINE__,cf)
|
||||||
#define forCellAll(ct, cf) forCellIdCM(ct,forCellAll ## __LINE__,cf)
|
#define forCellAll(ct, cf) forCellIdCM(ct,forCellAll ## __LINE__,cf)
|
||||||
|
|
||||||
/* conditions */
|
|
||||||
|
|
||||||
/** `IF_KEY_EXISTS(it, map, key) statement` checks whether the map 'map' contain key 'key', and if so, executes statement with it set to the relevant iterator */
|
|
||||||
#define IF_KEY_EXISTS(it, map, key) for(auto it: {map.find(key)}) if(it != map.end())
|
|
||||||
|
|
||||||
// canAttack/moveval flags
|
// canAttack/moveval flags
|
||||||
|
|
||||||
#define AF_NORMAL 0 // nothing special about this attack
|
#define AF_NORMAL 0 // nothing special about this attack
|
||||||
@ -851,6 +846,13 @@ template<class T> array<T, 4> make_array(T a, T b, T c, T d) { array<T,4> x; x[0
|
|||||||
template<class T> array<T, 3> make_array(T a, T b, T c) { array<T,3> x; x[0] = a; x[1] = b; x[2] = c; return x; }
|
template<class T> array<T, 3> make_array(T a, T b, T c) { array<T,3> x; x[0] = a; x[1] = b; x[2] = c; return x; }
|
||||||
template<class T> array<T, 2> make_array(T a, T b) { array<T,2> x; x[0] = a; x[1] = b; return x; }
|
template<class T> array<T, 2> make_array(T a, T b) { array<T,2> x; x[0] = a; x[1] = b; return x; }
|
||||||
|
|
||||||
|
// Find in a std::map or std::unordered_map, or return null.
|
||||||
|
template<class Map, class Key>
|
||||||
|
const typename Map::mapped_type *at_or_null(const Map& map, const Key& key) {
|
||||||
|
auto it = map.find(key);
|
||||||
|
return (it == map.end()) ? nullptr : &it->second;
|
||||||
|
}
|
||||||
|
|
||||||
namespace daily {
|
namespace daily {
|
||||||
extern bool on;
|
extern bool on;
|
||||||
extern int daily_id;
|
extern int daily_id;
|
||||||
|
28
util.cpp
28
util.cpp
@ -207,10 +207,10 @@ cld exp_parser::parse(int prio) {
|
|||||||
cld c = rparse(0);
|
cld c = rparse(0);
|
||||||
force_eat(")");
|
force_eat(")");
|
||||||
|
|
||||||
IF_KEY_EXISTS(it, extra_params, "angleunit") {
|
if (auto *angleunit = hr::at_or_null(extra_params, "angleunit")) {
|
||||||
a *= it->second;
|
a *= *angleunit;
|
||||||
b *= it->second;
|
b *= *angleunit;
|
||||||
c *= it->second;
|
c *= *angleunit;
|
||||||
}
|
}
|
||||||
|
|
||||||
return edge_of_triangle_with_angles(real(a), real(b), real(c));
|
return edge_of_triangle_with_angles(real(a), real(b), real(c));
|
||||||
@ -237,14 +237,14 @@ cld exp_parser::parse(int prio) {
|
|||||||
test.compute_sum();
|
test.compute_sum();
|
||||||
test.compute_geometry();
|
test.compute_geometry();
|
||||||
res = test.edgelength;
|
res = test.edgelength;
|
||||||
IF_KEY_EXISTS(it, extra_params, "distunit")
|
if (auto *distunit = hr::at_or_null(extra_params, "distunit"))
|
||||||
res /= it->second;
|
res /= *distunit;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else if(eat("regangle(")) {
|
else if(eat("regangle(")) {
|
||||||
cld edgelen = parse(0);
|
cld edgelen = parse(0);
|
||||||
IF_KEY_EXISTS(it, extra_params, "distunit") {
|
if (auto *distunit = hr::at_or_null(extra_params, "distunit")) {
|
||||||
edgelen = edgelen * it->second;
|
edgelen *= *distunit;
|
||||||
}
|
}
|
||||||
|
|
||||||
force_eat(",");
|
force_eat(",");
|
||||||
@ -260,14 +260,14 @@ cld exp_parser::parse(int prio) {
|
|||||||
|
|
||||||
if(arb::legacy) {
|
if(arb::legacy) {
|
||||||
res = M_PI - result;
|
res = M_PI - result;
|
||||||
IF_KEY_EXISTS(it, extra_params, "angleofs")
|
if (auto *angleofs = hr::at_or_null(extra_params, "angleofs"))
|
||||||
res -= it->second;
|
res -= *angleofs;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
res = result;
|
res = result;
|
||||||
|
|
||||||
IF_KEY_EXISTS(it, extra_params, "angleunit")
|
if (auto *angleunit = hr::at_or_null(extra_params, "angleunit"))
|
||||||
res /= it->second;
|
res /= *angleunit;
|
||||||
}
|
}
|
||||||
else if(eat("test(")) {
|
else if(eat("test(")) {
|
||||||
res = parsepar();
|
res = parsepar();
|
||||||
@ -318,8 +318,8 @@ cld exp_parser::parse(int prio) {
|
|||||||
else if(next() == '(') at++, res = parsepar();
|
else if(next() == '(') at++, res = parsepar();
|
||||||
else {
|
else {
|
||||||
string number = next_token();
|
string number = next_token();
|
||||||
IF_KEY_EXISTS(it, extra_params, number) res = it->second;
|
if (auto *p = hr::at_or_null(extra_params, number)) res = *p;
|
||||||
else IF_KEY_EXISTS(it, params, number) res = it->second->get_cld();
|
else if (auto *p = hr::at_or_null(params, number)) res = (*p)->get_cld();
|
||||||
else if(number == "e") res = exp(1);
|
else if(number == "e") res = exp(1);
|
||||||
else if(number == "i") res = cld(0, 1);
|
else if(number == "i") res = cld(0, 1);
|
||||||
else if(number == "p" || number == "pi") res = M_PI;
|
else if(number == "p" || number == "pi") res = M_PI;
|
||||||
|
Loading…
Reference in New Issue
Block a user