1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-26 18:10:35 +00:00
hyperrogue/racing.cpp

1319 lines
35 KiB
C++
Raw Normal View History

2018-11-17 18:30:50 +00:00
// Hyperbolic Rogue
// namespaces for complex features (whirlwind, whirlpool, elec, princess, clearing,
// mirror, hive, heat + livecaves, etc.)
// Copyright (C) 2011-2018 Zeno Rogue, see 'hyper.cpp' for details
namespace hr {
namespace racing {
void set_race_configurer();
2019-01-07 03:53:09 +00:00
bool guiding = false;
2018-11-17 18:30:50 +00:00
bool on;
bool player_relative = false;
2019-01-17 00:15:28 +00:00
bool standard_centering = false;
bool track_ready;
2018-11-17 18:30:50 +00:00
2019-01-11 01:19:28 +00:00
bool official_race = false;
int TWIDTH;
2018-12-23 13:01:07 +00:00
ld race_advance = 0;
static const int LENGTH = 250;
static const int DROP = 1;
2018-11-17 18:30:50 +00:00
int ghosts_to_show = 5;
int ghosts_to_save = 10;
struct race_cellinfo {
cell *c;
int from_track;
int completion;
2018-12-23 12:11:30 +00:00
int from_start, from_goal;
};
vector<race_cellinfo> rti;
2018-11-17 18:30:50 +00:00
vector<cell*> track;
map<cell*, int> rti_id;
2018-11-17 18:30:50 +00:00
2019-01-07 03:55:21 +00:00
int trophy[MAXPLAYER];
2018-11-24 02:26:07 +00:00
string track_code = "OFFICIAL";
transmatrix straight;
2018-11-25 22:39:47 +00:00
int race_try;
void apply_seed() {
2018-11-25 22:39:47 +00:00
int s = race_try;
for(char c: track_code) s = 713 * s + c;
shrand(s);
}
2018-11-24 02:26:07 +00:00
int race_start_tick, race_finish_tick[MAXPLAYER];
2018-11-26 22:17:43 +00:00
typedef unsigned char uchar;
uchar frac_to_uchar(ld x) { return uchar(x * 256); }
uchar angle_to_uchar(ld x) { return frac_to_uchar(x / 2 / M_PI); }
ld uchar_to_frac(uchar x) { return x / 256.; }
transmatrix spin_uchar(uchar x) { return spin(uchar_to_frac(x) * 2 * M_PI); }
static const ld distance_multiplier = 4;
2018-11-24 02:26:07 +00:00
struct ghostmoment {
2018-11-26 22:17:43 +00:00
int step, where_id;
uchar alpha, distance, beta, footphase;
2018-11-24 02:26:07 +00:00
};
struct ghost {
charstyle cs;
int result;
int checksum;
long long timestamp;
vector<ghostmoment> history;
};
2019-01-11 01:19:28 +00:00
typedef map<eLand, vector<ghost>> raceset;
2019-01-07 03:56:06 +00:00
map<pair<string, int>, raceset> race_ghosts;
2018-11-24 02:26:07 +00:00
2019-01-07 03:56:06 +00:00
map<pair<string, int>, raceset> official_race_ghosts;
raceset& ghostset() { return race_ghosts[make_pair(track_code, modecode())]; }
raceset& oghostset() { return official_race_ghosts[make_pair(track_code, modecode())]; }
2019-01-11 01:19:28 +00:00
int get_score_in_land(eLand l) {
auto& gh = ghostset();
if(!gh.count(l)) return 0;
auto& v = gh[l];
if(!isize(v)) return 0;
return v[0].result;
}
array<vector<ghostmoment>, MAXPLAYER> current_history;
2018-11-24 02:26:07 +00:00
2018-11-24 20:24:27 +00:00
string ghost_prefix = "default";
2019-02-17 17:58:49 +00:00
#if CAP_FILES
2018-11-24 20:24:27 +00:00
string ghost_filename(string seed, int mcode) {
if(ghost_prefix == "default") {
#ifdef FHS
if(getenv("HOME")) {
string s = getenv("HOME");
mkdir((s + "/.hyperrogue").c_str(), 0755);
mkdir((s + "/.hyperrogue/racing").c_str(), 0755);
ghost_prefix = s + "/.hyperrogue/racing/";
}
#else
2019-01-02 15:21:55 +00:00
#if WINDOWS
mkdir("racing");
#else
2018-11-24 20:24:27 +00:00
mkdir("racing", 0755);
2019-01-02 15:21:55 +00:00
#endif
2018-11-24 20:24:27 +00:00
ghost_prefix = "racing/";
#endif
}
return ghost_prefix + seed + "-" + itsh(mcode) + ".data";
}
void hread(hstream& hs, ghostmoment& m) {
2018-11-26 22:17:43 +00:00
hread(hs, m.step, m.where_id, m.alpha, m.distance, m.beta, m.footphase);
2018-11-24 20:24:27 +00:00
}
void hwrite(hstream& hs, const ghostmoment& m) {
2018-11-26 22:17:43 +00:00
hwrite(hs, m.step, m.where_id, m.alpha, m.distance, m.beta, m.footphase);
2018-11-24 20:24:27 +00:00
}
void hread(hstream& hs, ghost& gh) {
hread(hs, gh.cs, gh.result, gh.timestamp, gh.checksum, gh.history);
2018-11-24 20:24:27 +00:00
}
void hwrite(hstream& hs, const ghost& gh) {
hwrite(hs, gh.cs, gh.result, gh.timestamp, gh.checksum, gh.history);
2018-11-24 20:24:27 +00:00
}
bool read_ghosts(string seed, int mcode) {
if(seed == "OFFICIAL" && mcode == 2) {
2019-01-11 14:01:12 +00:00
fhstream f("officials.data", "rb");
f.get<int>();
hread(f, oghostset());
}
string fname = ghost_filename(seed, mcode);
println(hlog, "trying to read ghosts from: ", fname);
fhstream f(fname, "rb");
2018-11-24 20:24:27 +00:00
if(!f.f) return false;
2019-01-17 00:02:02 +00:00
int vernum = f.get<int> ();
if(vernum <= 0xA600) return true; // scores removed due to the possibility of cheating
2019-01-07 03:56:06 +00:00
hread(f, ghostset());
2018-11-24 20:24:27 +00:00
return true;
}
void write_ghosts(string seed, int mcode) {
fhstream f;
f.f = fopen(ghost_filename(seed, mcode).c_str(), "wb");
if(!f.f) throw hstream_exception(); // ("failed to write the ghost file");
hwrite(f, (const int&) VERNUM_HEX);
2019-01-07 03:56:06 +00:00
hwrite(f, ghostset());
2018-11-24 20:24:27 +00:00
}
2019-02-17 17:58:49 +00:00
#endif
2018-11-24 20:24:27 +00:00
2019-01-17 13:11:12 +00:00
transmatrix get_ghostmoment_matrix(ghostmoment& p) {
2019-01-07 03:56:06 +00:00
cell *w = rti[p.where_id].c;
transmatrix T = spin_uchar(p.alpha) * xpush(uchar_to_frac(p.distance) * distance_multiplier) * spin_uchar(p.beta);
return gmatrix[w] * T;
}
2018-11-24 00:30:05 +00:00
void fix_cave(cell *c) {
int v = 0;
// if(c->wall == waCavewall) v++;
// if(c->wall == waCavefloor) v--;
forCellEx(c2, c) {
if(c2->wall == waCavewall) v++;
if(c2->wall == waCavefloor) v--;
}
else v--;
if(v>0 && c->wall == waCavefloor) c->wall = waCavewall;
if(v<0 && c->wall == waCavewall) c->wall = waCavefloor;
}
2018-11-23 01:58:16 +00:00
bool bad(cell *c2, cell *c) {
2018-11-24 00:30:05 +00:00
if(c2->land == laCaves) {
forCellEx(c3, c2) fix_cave(c3);
fix_cave(c2);
}
2018-11-23 01:58:16 +00:00
if(!passable(c2, c, P_ISPLAYER)) return true;
if((c2->land == laCrossroads) ^ (c->land == laCrossroads)) return true;
return false;
}
2018-12-04 20:17:57 +00:00
int rcelldist(cell *c) {
2019-02-27 14:53:07 +00:00
#if CAP_CRYSTAL
2018-12-04 20:17:57 +00:00
if(geometry == gCrystal) return crystal::space_distance(c, currentmap->gamestart());
2019-02-27 14:53:07 +00:00
#endif
return celldist(c);
2018-12-04 20:17:57 +00:00
}
int pcelldist(cell *c) {
2019-02-27 14:53:07 +00:00
#if CAP_CRYSTAL
2018-12-04 20:17:57 +00:00
if(geometry == gCrystal) return crystal::precise_distance(c, currentmap->gamestart());
2019-02-27 14:53:07 +00:00
#endif
return celldist(c);
2018-12-04 20:17:57 +00:00
}
2018-11-17 18:30:50 +00:00
int trackval(cell *c) {
2018-12-04 20:17:57 +00:00
int v = rcelldist(c);
2018-11-17 18:30:50 +00:00
int bonus = 0;
2018-11-23 01:58:16 +00:00
if(c->land != laCrossroads)
2018-11-17 18:30:50 +00:00
forCellEx(c2, c) {
2018-12-04 20:17:57 +00:00
int d = rcelldist(c2) - v;
2018-11-23 01:58:16 +00:00
if(d < 0 && bad(c2, c))
2018-11-17 18:30:50 +00:00
bonus += 2;
2018-11-23 01:58:16 +00:00
if(d == 0 && bad(c2, c))
2018-11-17 18:30:50 +00:00
bonus ++;
}
return v + bonus;
}
void tie_info(cell *c, int from_track, int comp) {
rti_id[c] = isize(rti);
2018-12-23 12:11:30 +00:00
rti.emplace_back(race_cellinfo{c, from_track, comp, -1, -1});
}
race_cellinfo& get_info(cell *c) {
return rti[rti_id.at(c)];
}
int race_checksum;
2018-11-25 22:39:47 +00:00
ld start_line_width;
2018-11-17 18:30:50 +00:00
void generate_track() {
TWIDTH = getDistLimit() - 1;
if(binarytiling && DIM == 3) TWIDTH++;
2019-02-17 17:58:49 +00:00
#if CAP_FILES
2019-01-07 03:56:06 +00:00
if(ghostset().empty())
2018-11-24 20:24:27 +00:00
read_ghosts(track_code, modecode());
2019-02-17 17:58:49 +00:00
#endif
2018-11-24 20:24:27 +00:00
2018-11-17 18:30:50 +00:00
track.clear();
/*
int t = -1;
bignum full_id;
bool onlychild = true;
*/
cell *s = currentmap->gamestart();
2018-11-25 22:39:47 +00:00
if(specialland == laCrossroads) {
celllister cl(s, TWIDTH, 1000000, NULL);
for(cell *c: cl.lst) c->bardir = NOBARRIERS;
}
2019-02-27 14:53:22 +00:00
int dl = 7 - getDistLimit() - genrange_bonus;
2018-11-25 22:39:47 +00:00
2018-11-17 18:30:50 +00:00
setdist(s, 6, NULL);
makeEmpty(s);
map<cell*, cell*> parent;
map<int, vector<cell*> > cellbydist;
cellbydist[0].push_back(s);
cell *goal;
2018-11-24 00:30:05 +00:00
int traversed = 0;
2018-11-25 22:39:47 +00:00
2018-11-17 18:30:50 +00:00
while(true) {
2018-11-24 00:30:05 +00:00
traversed++;
2018-11-17 18:30:50 +00:00
if(cellbydist.empty()) {
2018-11-24 00:30:05 +00:00
printf("reset after traversing %d\n", traversed);
2018-11-25 22:39:47 +00:00
race_try++;
gamegen_failure = true;
2018-11-17 18:30:50 +00:00
return;
}
auto it = cellbydist.end();
it--;
// if(hrand(100) < 85 && it != cellbydist.begin()) it--;
auto& v = it->second;
if(v.empty()) { cellbydist.erase(it); continue; }
int id = hrand(isize(v));
cell *c = v[id];
v[id] = v.back(); v.pop_back();
if(it->first >= LENGTH) {
goal = c;
break;
}
2019-02-27 14:53:22 +00:00
setdist(c, (8 + dl) / 2, parent[c]);
2018-11-23 01:58:16 +00:00
forCellEx(c1, c) if(!bad(c1, c) && !parent.count(c1)) {
2018-11-17 18:30:50 +00:00
parent[c1] = c;
cellbydist[trackval(c1)].push_back(c1);
}
}
2018-12-04 21:35:13 +00:00
track = build_shortest_path(s, goal);
2018-11-17 18:30:50 +00:00
/*
transmatrix At = spin(hrand(1000));
track.push_back(s);
while(isize(track) < LENGTH) {
At = At * xpush(.1);
cell *sb = s;
virtualRebase(s, At, true);
fixmatrix(At);
if(s != sb) track.push_back(s);
}
*/
/*
cellwalker ycw(s, hrand(s->type));
track.push_back(s);
for(int i=0; i<LENGTH; i++) {
if(i == 0) {
t = type_in(expansion, s, celldist);
bignum b = expansion.get_descendants(LENGTH, t);
full_id = hrand(b);
}
if(i == 1)
onlychild = true;
if(!onlychild) ycw++;
if(VALENCE == 3) ycw++;
onlychild = false;
for(int tch: expansion.children[t]) {
ycw++;
if(i == 1)
tch = type_in(expansion, ycw.cpeek(), celldist);
auto& sub_id = expansion.get_descendants(LENGTH-i-1, tch);
if(full_id < sub_id) { t = tch; break; }
full_id.addmul(sub_id, -1);
onlychild = true;
}
ycw += wstep;
track.push_back(ycw.at);
}
for(int a = 0; a < 2; a++)
for(int i=0; i<isize(track)-1; i++) {
cell *cx = track[min(i + 10, isize(track)-1)];
ld err = HUGE_VAL;
forCellEx(c2, track[i]) {
ld dist = hdist0(calc_relative_matrix(cx, c2, C0) * C0);
if(dist < err) err = dist, track[i+1] = c2;
}
} */
// for(cell *c:track) if(c->land != laMirror) c->bardir = NOBARRIERS;
2019-02-27 14:53:22 +00:00
for(cell *c:track) setdist(c, dl, NULL);
2018-11-17 18:30:50 +00:00
2018-11-18 00:42:17 +00:00
if(1) {
manual_celllister cl;
2018-11-17 18:30:50 +00:00
for(int i=0; i<isize(track); i++) {
tie_info(track[i], 0, i);
2018-11-18 00:42:17 +00:00
cl.add(track[i]);
}
int win = isize(track) - DROP;
2018-11-18 00:42:17 +00:00
for(int i=0; i<isize(cl.lst); i++) {
cell *c = cl.lst[i];
auto p = get_info(c);
forCellEx(c2, c) if(!rti_id.count(c2)) {
tie_info(c2, p.from_track+1, p.completion);
2018-11-18 00:42:17 +00:00
cl.add(c2);
}
c->item = itNone;
if(c->wall == waMirror || c->wall == waCloud) c->wall = waNone;
if(!isIvy(c))
c->monst = moNone;
2018-11-24 00:30:05 +00:00
if(c->monst == moIvyHead) c->monst = moIvyWait;
2018-11-18 00:42:17 +00:00
if(inmirror(c->land))
;
else if(p.from_track == TWIDTH) {
2018-11-24 00:30:05 +00:00
killMonster(c, moNone, 0);
c->wall = waBarrier;
2018-11-18 00:42:17 +00:00
c->land = laBarrier;
2018-11-24 00:30:05 +00:00
}
else if(p.from_track > TWIDTH) {
2018-11-24 00:30:05 +00:00
killMonster(c, moNone, 0);
c->land = laMemory;
2018-11-18 00:42:17 +00:00
c->wall = waChasm;
2018-11-24 00:30:05 +00:00
}
if(p.completion >= win && p.from_track < TWIDTH) {
2018-11-24 00:30:05 +00:00
c->wall = hrand(2) ? waMirror : waCloud;
killMonster(c, moNone, 0);
}
2018-11-17 18:30:50 +00:00
}
}
int byat[256];
for(int a=0; a<16; a++) byat[a] = 0;
for(const auto s: rti) byat[s.from_track]++;
2018-11-17 18:30:50 +00:00
for(int a=0; a<16; a++) printf("%d: %d\n", a, byat[a]);
2018-11-24 00:30:05 +00:00
if(s->land == laCaves) {
set<unsigned> hash;
while(true) {
unsigned hashval = 7;
int id = 0;
for(auto s: rti) {
fix_cave(s.c);
if(s.c->wall == waCavewall)
2018-11-24 00:30:05 +00:00
hashval = (3+2*(id++)) * hashval + 1;
if(s.c->wall == waCavefloor)
2018-11-24 00:30:05 +00:00
hashval = (3+2*(id++)) * hashval + 2;
}
printf("hashval = %x id = %d\n", hashval, id);
if(hash.count(hashval)) break;
hash.insert(hashval);
}
}
2018-11-25 22:39:47 +00:00
for(cell *sc: track) {
straight = calc_relative_matrix(sc, track[0], C0);
2019-02-27 12:34:52 +00:00
if(straight[DIM][DIM] > 1e8) break;
2018-11-25 22:39:47 +00:00
}
straight = rspintox(straight * C0);
ld& a = start_line_width;
2019-02-27 12:34:52 +00:00
if(DIM == 2) for(a=0; a<10; a += .1) {
2018-11-25 22:39:47 +00:00
hyperpoint h = straight * parabolic1(a) * C0;
cell *at = s;
virtualRebase(at, h, true);
if(!rti_id.count(at) || get_info(at).from_track >= TWIDTH) break;
}
2019-02-27 12:34:52 +00:00
if(DIM == 2) for(ld cleaner=0; cleaner<a*.75; cleaner += .2) for(int dir=-1; dir<=1; dir+=2) {
2018-11-25 22:39:47 +00:00
transmatrix T = straight * parabolic1(cleaner * dir);
cell *at = s;
virtualRebase(at, T, true);
2018-12-23 12:11:30 +00:00
get_info(at).from_start = 0;
2018-11-25 22:39:47 +00:00
for(ld u=0; u<50; u++) {
if(at->wall != waBarrier)
makeEmpty(at);
killMonster(at, moNone, 0);
T = T * xpush(.1);
virtualRebase(at, T, true);
}
}
for(auto s: rti) if(s.c->monst == moIvyDead) s.c->monst = moNone;
for(int i=0; i<motypes; i++) kills[i] = 0;
2019-01-07 03:55:21 +00:00
2019-01-07 03:56:06 +00:00
vector<transmatrix> forbidden;
for(auto& ghost: ghostset()[specialland])
2019-01-17 13:11:12 +00:00
forbidden.push_back(get_ghostmoment_matrix(ghost.history[0]));
for(auto& ghost: oghostset()[specialland])
forbidden.push_back(get_ghostmoment_matrix(ghost.history[0]));
2019-01-07 03:56:06 +00:00
2019-01-07 03:55:21 +00:00
for(int i=0; i<multi::players; i++) trophy[i] = 0;
2018-11-25 22:39:47 +00:00
for(int i=0; i<multi::players; i++) {
auto who = shmup::pc[i];
// this is intentionally not hrand
2019-01-07 03:56:06 +00:00
for(int j=0; j<100; j++) {
2019-02-27 12:34:52 +00:00
if(DIM == 3)
who->at = Id; // straight * cspin(0, 2, rand() % 360) * cspin(1, 2, rand() % 360);
else
who->at = straight * parabolic1(start_line_width * (rand() % 20000 - 10000) / 40000) * spin(rand() % 360);
2019-01-07 03:56:06 +00:00
who->base = s;
bool ok = true;
for(const transmatrix& t: forbidden) if(hdist(t*C0, who->at * C0) < 10. / (j+10)) ok = false;
if(ok) break;
}
2018-11-25 22:39:47 +00:00
virtualRebase(who, true);
}
2018-11-18 00:42:17 +00:00
if(1) {
manual_celllister cl;
cl.add(s);
bool goal = false;
for(int i=0; i<isize(cl.lst); i++) {
cell *c = cl.lst[i];
forCellEx(c2, c) {
if(among(c2->wall, waCloud, waMirror)) goal = true;
if(passable(c2, c, P_ISPLAYER))
2018-11-18 00:42:17 +00:00
cl.add(c2);
}
}
if(!goal) {
printf("error: goal unreachable\n");
gamegen_failure = true;
2018-11-25 22:39:47 +00:00
race_try++;
2018-11-18 00:42:17 +00:00
return;
}
}
2018-12-23 12:11:30 +00:00
if(1) {
map<cell*, pair<int, int> > cdists;
manual_celllister cl;
cl.add(s);
for(auto cc: rti) if(cc.from_start == 0) cl.add(cc.c);
for(int i=0; i<isize(cl.lst); i++) {
cell *c = cl.lst[i];
forCellEx(c2, c) {
if(passable(c2, c, P_ISPLAYER) && !cl.listed(c2))
cl.add(c2), get_info(c2).from_start = get_info(c).from_start + 1;
}
}
}
if(1) {
map<cell*, pair<int, int> > cdists;
manual_celllister cl;
for(auto cc: rti) if(among(cc.c->wall, waCloud, waMirror))
cc.from_goal = 0, cl.add(cc.c);
for(int i=0; i<isize(cl.lst); i++) {
cell *c = cl.lst[i];
forCellEx(c2, c) {
if(passable(c2, c, P_ISPLAYER) && !cl.listed(c2))
cl.add(c2), get_info(c2).from_goal = get_info(c).from_goal + 1;
}
}
}
int total_track = get_info(s).from_goal;
auto blockoff = [&total_track] (race_cellinfo& cc) {
if(cc.from_start < 1 || cc.from_goal < 1) return false;
int dif = cc.from_start + cc.from_goal - 2 * cc.from_track - total_track;
return dif > 3;
};
auto blockbound = [&blockoff] (cell *c) {
forCellEx(c2, c) if(passable(c2, c, P_ISPLAYER) && !blockoff(get_info(c2))) return true;
return false;
};
vector<cell*> to_block;
for(auto cc: rti) if(blockoff(cc)) to_block.push_back(cc.c);
hrandom_shuffle(&to_block[0], isize(to_block));
for(cell *c: to_block) switch(specialland) {
case laIce:
c->wall = waIcewall;
break;
case laHell:
c->wall = waSulphur;
break;
case laJungle: {
vector<int> dirs;
forCellIdEx(c2, i, c) if(among(c2->monst, moIvyRoot, moIvyWait)) dirs.push_back(i);
if(dirs.empty()) c->monst = moIvyRoot;
else c->monst = moIvyWait, c->mondir = dirs[hrand(isize(dirs))];
break;
}
case laDeadCaves:
if(blockbound(c)) c->wall = waDeadwall;
break;
case laRedRock:
if(blockbound(c)) c->wall = waRed3;
break;
case laDragon:
c->wall = waChasm;
break;
case laDryForest:
if(blockbound(c)) c->wall = waBigTree;
break;
case laDesert:
if(blockbound(c)) c->wall = waDune;
break;
case laRuins:
if(blockbound(c)) c->wall = waRuinWall;
break;
case laElementalWall:
if(blockbound(c)) {
if(c->land == laEFire) c->wall = waEternalFire;
else if(c->land == laEWater) c->wall = waSea;
else if(c->land == laEAir) c->wall = waChasm;
else if(c->land == laEEarth) c->wall = waStone;
}
break;
default: break;
}
// for(cell *c: to_block) if(blockbound(c)) c->land = laOvergrown;
2018-11-17 18:30:50 +00:00
/*
for(cell *c: track) {
int i = trackval(c) - celldist(c);
if(i == 0) c->item = itDiamond;
if(i == 1) c->item = itGold;
if(i == 2) c->item = itEmerald;
if(i == 3) c->item = itSapphire;
if(i == 4) c->item = itRuby;
if(i >= 5) c->item = itBone;
}
*/
track_ready = true;
race_checksum = hrand(1000000);
2018-11-24 02:26:07 +00:00
race_start_tick = 0;
for(int i=0; i<MAXPLAYER; i++) race_finish_tick[i] = 0;
2019-01-11 01:19:28 +00:00
official_race = (track_code == "OFFICIAL" && modecode() == 2);
if(official_race && race_checksum != oghostset() [specialland] [0].checksum) {
official_race = false;
addMessage(XLAT("Race did not generate correctly for some reason -- not ranked"));
}
2018-11-17 18:30:50 +00:00
}
bool inrec = false;
ld race_angle = 90;
void set_view() {
2019-03-09 15:20:06 +00:00
multi::cpid = subscreens::in ? subscreens::current_player : 0;
2018-11-24 02:26:07 +00:00
2019-03-09 15:20:06 +00:00
if(race_start_tick == 0) race_start_tick = ticks + 5000;
2018-11-17 18:30:50 +00:00
2019-03-09 15:20:06 +00:00
shmup::monster *who = shmup::pc[multi::cpid];
2018-11-17 18:30:50 +00:00
2018-11-26 22:17:43 +00:00
if(!inrec) {
const transmatrix T = who->at;
ld alpha = -atan2(T * C0);
ld distance = hdist0(T * C0);
ld beta = -atan2(xpush(-distance) * spin(-alpha) * T * Cx1);
2019-03-09 15:20:06 +00:00
current_history[multi::cpid].emplace_back(ghostmoment{ticks - race_start_tick, rti_id[who->base],
2018-11-26 22:17:43 +00:00
angle_to_uchar(alpha),
frac_to_uchar(distance / distance_multiplier),
angle_to_uchar(beta),
frac_to_uchar(who->footphase)
});
}
2018-11-17 18:30:50 +00:00
2019-02-27 17:00:50 +00:00
if(DIM == 3) return;
2019-01-10 02:06:48 +00:00
transmatrix at = ypush(-vid.yshift) * ggmatrix(who->base) * who->at;
2018-11-17 18:30:50 +00:00
if(racing::player_relative || quotient)
2018-11-17 18:30:50 +00:00
View = spin(race_angle * degree) * inverse(at) * View;
else {
int z = get_info(who->base).completion;
2018-11-17 18:30:50 +00:00
int steps = euclid ? 1000 : 20;
cell *c1 = racing::track[max(z-steps, 0)];
cell *c2 = racing::track[min(z+steps, isize(racing::track)-1)];
2019-01-10 02:06:48 +00:00
transmatrix T1 = ypush(-vid.yshift) * ggmatrix(c1);
transmatrix T2 = ypush(-vid.yshift) * ggmatrix(c2);
2018-11-17 18:30:50 +00:00
transmatrix T = spintox(inverse(T1) * T2 * C0);
hyperpoint h = T * inverse(T1) * at * C0;
ld y = asin_auto(h[1]);
ld x = asin_auto(h[0] / cos_auto(y));
2018-12-23 13:01:07 +00:00
x += race_advance;
2018-11-17 18:30:50 +00:00
// printf("%d %lf\n", z, x);
transmatrix Z = T1 * inverse(T) * xpush(x);
View = spin(race_angle * degree) * inverse(Z) * View;
}
}
#if CAP_COMMANDLINE
void show();
int readArgs() {
using namespace arg;
if(0) ;
else if(argis("-racing")) {
PHASEFROM(2);
stop_game();
switch_game_mode(rg::racing);
2018-11-17 18:30:50 +00:00
}
else return 1;
return 0;
}
#endif
int tstart, tstop;
heptspin sview;
/*
void restore_time(int t) {
tuple<int, cell*, transmatrix, ld> sf = make_tuple(t, nullptr, Id, 0);
auto it = lower_bound(history.begin(), history.end(), sf, [] (auto a, auto b) { return get<0>(a) < get<0>(b); });
auto& m = shmup::pc[0];
tie(t, m->base, m->at, m->footphase) = *it;
shmup::pc[0]->pat = ggmatrix(shmup::pc[0]->base) * shmup::pc[0]->at;
}
*/
/*
bool akh(int sym, int uni) {
if(uni == '1') { tstart = ticks; sview = viewctr; }
else if(uni == '2') { tstop = ticks; }
else if(uni == '3') { conformal::model_orientation = 90; pmodel = mdBand; player_relative = false; }
else if(uni == '4') { conformal::model_orientation = 180; pmodel = mdHalfplane; conformal::halfplane_scale = 2; player_relative = false; }
else if(uni == '5') { pmodel = mdDisk; player_relative = true; }
else if(uni == '6') { vid.use_smart_range = true; vid.smart_range_detail = 2; }
else if(uni == '7' && tstart && tstop) {
viewctr = sview;
nohud = true;
restore_time(tstart);
drawthemap();
centerpc(0);
int t = tstart;
int i = 0;
inrec = true;
while(t < tstop) {
ticks = t;
char buf[1000];
restore_time(t);
shmup::fixStorage();
centerpc(0);
optimizeview();
cwt.at = shmup::pc[0]->base;
drawthemap();
fullcenter();
cmode = sm::NORMAL;
drawthemap();
centerpc(0);
optimizeview();
snprintf(buf, 1000, "animations/race/race%d-%03d.png", int(pmodel), i++);
saveHighQualityShot(buf);
t += 40;
}
inrec = false;
}
else return false;
return true;
}
*/
#if CAP_COMMANDLINE
auto hook =
addHook(hooks_args, 100, readArgs)
+ addHook(clearmemory, 0, []() {
track_ready = false;
track.clear();
rti.clear();
rti_id.clear();
for(auto &ch: current_history) ch.clear();
})
2018-11-17 18:30:50 +00:00
// + addHook(hooks_handleKey, 120, akh);
;
#endif
vector<eLand> race_lands = {
2018-11-23 01:58:16 +00:00
laHunting,
2018-11-24 00:30:05 +00:00
laCrossroads,
laJungle,
laDesert,
2018-11-17 18:30:50 +00:00
laRedRock,
laDragon,
laMirror,
2018-11-17 18:30:50 +00:00
laRuins,
laCaves,
laWildWest,
laIce,
laHell,
laTerracotta,
laElementalWall,
laDryForest,
laDeadCaves,
2018-11-17 18:30:50 +00:00
};
2018-11-18 02:44:23 +00:00
vector<string> playercmds_race = {
"forward", "backward", "turn left", "turn right",
"forward", "backward", "turn left", "turn right",
"", "", "",
"", "change camera", "", ""
};
string racetimeformat(int t) {
string times = "";
int digits = 0;
bool minus = (t < 0);
if(t < 0) t = -t;
while(t || digits < 6) {
int mby = (digits == 4 ? 6 : 10);
times = char('0'+(t%mby)) + times;
t /= mby; digits++;
if(digits == 3) times = "." + times;
if(digits == 5) times = ":" + times;
}
if(minus) times = "-" + times;
return times;
}
extern int playercfg;
2018-11-24 21:50:35 +00:00
void track_chooser(string new_track) {
cmode = 0;
gamescreen(2);
dialog::init(XLAT("Racing"));
2019-01-11 01:19:28 +00:00
map<char, eLand> landmap;
dynamicval<bool> so(shmup::on, true);
dynamicval<bool> ro(racing::on, true);
char let = 'a';
for(eLand l: race_lands) {
auto& ghs = race_ghosts[make_pair(new_track, modecode())];
const int LOST = 3600000;
int best = LOST;
if(ghs.count(l)) {
auto& gh = ghs[l];
for(auto& gc: gh) best = min(best, gc.result);
}
string s = (best == LOST) ? "" : racetimeformat(best);
2019-01-11 01:19:28 +00:00
landmap[let] = l;
dialog::addSelItem(XLAT1(linf[l].name), s, let++);
2018-11-24 21:50:35 +00:00
dialog::add_action([l, new_track] () {
stop_game();
multi::players = playercfg;
if(!racing::on) switch_game_mode(rg::racing);
track_code = new_track;
specialland = l;
// because of an earlier issue, some races in the Official track start with race_try = 1
race_try = among(l, laCaves, laWildWest, laHell, laTerracotta, laElementalWall, laDryForest, laDeadCaves) ? 1 : 0;
start_game();
popScreenAll();
});
}
dialog::addBack();
dialog::display();
if(landmap.count(getcstat) && new_track == "OFFICIAL" && modecode() == 2)
displayScore(landmap[getcstat]);
}
void race_projection() {
cmode = sm::SIDE | sm::MAYDARK;
gamescreen(1);
dialog::init(XLAT("racing projections"));
dialog::addBoolItem(XLAT("Poincaré disk model"), pmodel == mdDisk && !vid.camera_angle, '1');
dialog::add_action([] () {
pmodel = mdDisk;
race_advance = 0;
vid.yshift = 0;
vid.camera_angle = 0;
vid.xposition = 0;
vid.yposition = 0;
vid.scale = 1;
2019-01-11 14:01:36 +00:00
vid.use_smart_range = 0;
vid.smart_range_detail = 3;
});
dialog::addBoolItem(XLAT("band"), pmodel == mdBand, '2');
dialog::add_action([] () {
pmodel = mdBand;
conformal::model_orientation = race_angle;
race_advance = 1;
vid.yshift = 0;
vid.camera_angle = 0;
vid.xposition = 0;
vid.yposition = 0;
vid.scale = 1;
2019-01-11 14:01:36 +00:00
vid.use_smart_range = 1;
vid.smart_range_detail = 3;
});
dialog::addBoolItem(XLAT("half-plane"), pmodel == mdHalfplane, '3');
dialog::add_action([] () {
pmodel = mdHalfplane;
conformal::model_orientation = race_angle + 90;
race_advance = 0.5;
vid.yshift = 0;
vid.camera_angle = 0;
vid.xposition = 0;
vid.yposition = 0;
vid.scale = 1;
2019-01-11 14:01:36 +00:00
vid.use_smart_range = 1;
vid.smart_range_detail = 3;
});
dialog::addBoolItem(XLAT("third-person perspective"), pmodel == mdDisk && vid.camera_angle, '4');
dialog::add_action([] () {
pmodel = mdDisk;
race_advance = 0;
vid.yshift = -0.3;
vid.camera_angle = -45;
vid.scale = 18/16. * vid.xres / vid.yres / multi::players;
vid.xposition = 0;
2019-01-11 14:01:36 +00:00
vid.yposition = -0.9;
vid.use_smart_range = 1;
vid.smart_range_detail = 3;
});
if(pmodel == mdDisk) {
2019-01-17 00:15:28 +00:00
dialog::addSelItem(XLAT("point of view"), XLAT(player_relative ? "player" : "track"), 'p');
if(quotient || racing::standard_centering)
dialog::lastItem().value = XLAT("N/A");
dialog::add_action([] () {
player_relative = !player_relative;
if(pmodel == mdBand || pmodel == mdHalfplane)
pmodel = mdDisk;
if(racing::on)
set_view();
});
}
else dialog::addBreak(100);
dialog::addSelItem(XLAT("race angle"), fts(race_angle), 'a');
dialog::add_action([] () {
dialog::editNumber(race_angle, 0, 360, 15, 90, XLAT("race angle"), "");
int q = conformal::model_orientation - race_angle;
dialog::reaction = [q] () { conformal::model_orientation = race_angle + q; };
});
dialog::addSelItem(XLAT("show more in front"), fts(race_advance), 'A');
dialog::add_action([] () {
dialog::editNumber(race_advance, 0, 360, 0.1, 1, XLAT("show more in front"), "");
});
2019-01-17 00:15:28 +00:00
dialog::addBoolItem(XLAT("do not use special centering for racing"), standard_centering, 'C');
dialog::add_action([] () {
standard_centering = !standard_centering;
});
dialog::addBack();
dialog::display();
}
2018-11-18 02:44:23 +00:00
int playercfg;
2018-11-24 21:50:35 +00:00
bool editing_track;
string new_track;
/* struct race_configurer { */
void set_race_configurer() { editing_track = false; new_track = track_code; playercfg = multi::players; }
2018-11-24 21:50:35 +00:00
static string random_track_name() {
string s = "";
for(int a = 0; a < 4; a++) {
int u = rand() % 2;
if(u == 0)
s += "AEIOUY" [ rand() % 6];
s += "BCDFGHJKLMNPRSTVWZ" [ rand() % 18];
if(u == 1)
s += "AEIOUY" [ rand() % 6];
}
return s;
}
2018-11-18 02:44:23 +00:00
2018-11-24 21:50:35 +00:00
static string racecheck(int sym, int uni) {
if(uni >= 'A' && uni <= 'Z') return string("") + char(uni);
if(uni >= 'a' && uni <= 'z') return string("") + char(uni - 32);
return "";
}
void raceconfigurer() {
2018-11-18 02:44:23 +00:00
gamescreen(1);
dialog::init(XLAT("Racing"));
if(bounded)
dialog::addInfo(XLAT("Racing available only in unbounded worlds."), 0xFF0000);
else {
dialog::addItem(XLAT("select the track and start!"), 's');
dialog::add_action([/*this*/] () {
dynamicval<bool> so(shmup::on, true);
dynamicval<bool> ro(racing::on, true);
2019-02-17 17:58:49 +00:00
#if CAP_FILES
2019-01-07 03:56:06 +00:00
if(race_ghosts[make_pair(new_track, modecode())].empty())
read_ghosts(new_track, modecode());
else
2019-01-07 03:56:06 +00:00
println(hlog, "known ghosts: ", isize(race_ghosts[make_pair(new_track, modecode())]));
2019-02-17 17:58:49 +00:00
#endif
pushScreen([/*this*/] () { track_chooser(new_track); });
});
}
dialog::addBreak(100);
dialog::addItem(XLAT("configure the projection"), 'p');
dialog::add_action([] () { pushScreen(race_projection); });
2018-11-18 02:44:23 +00:00
2019-01-07 03:53:09 +00:00
dialog::addBoolItem(XLAT("guiding line"), guiding, 'g');
dialog::add_action([] () { guiding = !guiding; });
2018-11-18 02:44:23 +00:00
dialog::addItem(shmup::player_count_name(playercfg), 'n');
dialog::add_action([/*this*/] () {
2018-11-18 02:44:23 +00:00
playercfg = playercfg == 1 ? 2 : 1;
});
dialog::addItem(XLAT("configure player 1"), '1');
dialog::add_action([] () {
pushScreen(shmup::key_configurer(1, playercmds_race));
});
if(playercfg >= 2) {
dialog::addItem(XLAT("configure player 2"), '2');
dialog::add_action([] () {
pushScreen(shmup::key_configurer(2, playercmds_race));
});
2018-11-17 18:30:50 +00:00
}
2018-11-18 02:44:23 +00:00
else dialog::addBreak(100);
2018-11-24 21:50:35 +00:00
2019-01-03 18:58:53 +00:00
dialog::addBreak(100);
2019-01-18 20:03:55 +00:00
dialog::addSelItem(XLAT("track seed"), editing_track ? dialog::view_edited_string() : new_track, '/');
dialog::add_action([/*this*/] () {
2019-01-03 18:58:53 +00:00
editing_track = !editing_track;
if(editing_track) dialog::start_editing(new_track);
});
2019-01-18 20:03:55 +00:00
dialog::addItem(XLAT("play the official seed"), 'o');
dialog::add_action([/*this*/] () { new_track = "OFFICIAL"; });
2019-01-18 20:03:55 +00:00
dialog::addItem(XLAT("play a random seed"), 'r');
dialog::add_action([/*this*/] () { new_track = random_track_name(); });
2019-01-03 18:58:53 +00:00
dialog::addBreak(100);
dialog::addSelItem(XLAT("best scores to show as ghosts"), its(ghosts_to_show), 'c');
dialog::add_action([]() { dialog::editNumber(ghosts_to_show, 0, 100, 1, 5, "best scores to show as ghosts", ""); });
dialog::addSelItem(XLAT("best scores to save"), its(ghosts_to_save), 'b');
dialog::add_action([]() { dialog::editNumber(ghosts_to_save, 0, 100, 1, 10, "best scores to save", ""); });
if(racing::on) {
dialog::addItem(XLAT("disable the racing mode"), 'x');
dialog::add_action([] () {
stop_game();
switch_game_mode(rg::racing);
2018-11-25 22:39:47 +00:00
race_try = 0;
if(geometry == gNormal) specialland = firstland = laIce;
start_game();
});
}
2018-11-18 02:44:23 +00:00
dialog::addBack();
dialog::display();
2018-11-24 21:50:35 +00:00
keyhandler = [/*this*/] (int sym, int uni) {
2018-11-24 21:50:35 +00:00
if(editing_track) {
if(sym == SDLK_RETURN) sym = uni = '/';
if(dialog::handle_edit_string(sym, uni, racecheck)) return;
}
dialog::handleNavigation(sym, uni);
if(doexiton(sym, uni)) { if(editing_track) editing_track = false; else popScreen(); }
};
2018-11-18 02:44:23 +00:00
}
/* }; */
2018-11-17 18:30:50 +00:00
void configure_race() {
set_race_configurer();
pushScreen(raceconfigurer);
}
2018-11-18 02:44:23 +00:00
auto hooks1 =
addHook(hooks_o_key, 90, [] {
if(racing::on) { set_race_configurer(); return named_dialog(XLAT("racing menu"), raceconfigurer); }
2018-11-18 02:44:23 +00:00
else return named_functionality();
2018-11-17 18:30:50 +00:00
});
2019-01-11 01:19:28 +00:00
map<string, map<eLand, int> > scoreboard;
void uploadScore() {
int tscore = 0;
for(eLand l: race_lands) {
int i = get_score_in_land(l);
if(!i) continue;
2019-01-17 13:08:10 +00:00
scoreboard[myname()][l] = i;
2019-01-11 01:19:28 +00:00
int score = 60000000 / i; // 1000 points for minute, 2000 points for 30 sec
tscore += score;
}
achievement_score(LB_RACING, tscore);
}
void displayScore(eLand l) {
int vf = min((vid.yres-64) / 70, vid.xres/80);
int x = vid.xres / 4;
2019-01-14 22:00:17 +00:00
set_priority_board(LB_RACING);
2019-01-11 01:19:28 +00:00
if(get_sync_status() == 1) {
displayfr(x, 56, 1, vf, "(syncing)", 0xC0C0C0, 0);
}
else {
vector<pair<int, string> > scores;
for(auto p: scoreboard) if(p.second.count(l)) scores.emplace_back(p.second[l], p.first);
sort(scores.begin(), scores.end());
int i = 0;
for(auto& sc: scores) {
int i0 = 56 + (i++) * vf;
displayfr(x, i0, 1, vf, racetimeformat(sc.first), 0xC0C0C0, 16);
displayfr(x+8, i0, 1, vf, sc.second, 0xC0C0C0, 0);
}
}
}
void race_won() {
2019-03-09 15:20:06 +00:00
if(!race_finish_tick[multi::cpid]) {
2019-01-07 03:55:21 +00:00
int result = ticks - race_start_tick;
int losers = 0;
int place = 1;
for(int i=0; i<multi::players; i++) if(race_finish_tick[i]) place++; else losers = 0;
for(auto& ghost: ghostset()[specialland]) if(ghost.result < result) place++; else losers++;
for(auto& ghost: oghostset()[specialland]) if(ghost.result < result) place++; else losers++;
2019-03-09 15:20:06 +00:00
if(place == 1 && losers) trophy[multi::cpid] = 0xFFD500FF;
if(place == 2) trophy[multi::cpid] = 0xFFFFC0FF;
if(place == 3) trophy[multi::cpid] = 0x967444FF;
2019-01-17 13:12:26 +00:00
if(place + losers > 1)
addMessage(XLAT("Finished the race! Time: %1, place: %2 out of %3", racetimeformat(result), its(place), its(place+losers)));
else
addMessage(XLAT("Finished the race in time %1!", racetimeformat(result)));
2019-01-07 03:55:21 +00:00
2019-01-11 01:19:28 +00:00
if(place == 1 && losers && official_race)
achievement_gain("RACEWON", rg::racing);
2019-03-09 15:20:06 +00:00
race_finish_tick[multi::cpid] = ticks;
charstyle gcs = getcs();
2018-11-24 20:24:27 +00:00
for(color_t *x: {&gcs.skincolor, &gcs.haircolor, &gcs.dresscolor, &gcs.swordcolor, &gcs.dresscolor2}) {
for(int a=1; a<4; a++)
part(*x, a) = (part(*x, a) + part(gcs.uicolor, a)) / 2;
part(*x, 0) >>= 2;
}
2019-01-07 03:56:06 +00:00
auto &subtrack = ghostset() [specialland];
int ngh = 0;
for(int i=0; i<isize(subtrack); i++) {
if(subtrack[i].checksum != race_checksum) {
println(hlog, format("wrong checksum: %x, should be %x", subtrack[i].checksum, race_checksum));
}
else {
if(i != ngh)
subtrack[ngh] = move(subtrack[i]);
ngh++;
}
}
subtrack.resize(ngh);
2019-03-09 15:20:06 +00:00
subtrack.emplace_back(ghost{gcs, result, race_checksum, time(NULL), current_history[multi::cpid]});
2019-01-07 03:56:06 +00:00
sort(subtrack.begin(), subtrack.end(), [] (const ghost &g1, const ghost &g2) { return g1.result < g2.result; });
if(isize(subtrack) > ghosts_to_save && ghosts_to_save > 0)
subtrack.resize(ghosts_to_save);
2019-02-28 14:06:23 +00:00
#if CAP_FILES
if(ghosts_to_save > 0)
write_ghosts(track_code, modecode());
2019-02-28 14:06:23 +00:00
#endif
2019-01-11 01:19:28 +00:00
if(official_race) uploadScore();
}
}
2019-01-17 13:11:12 +00:00
void draw_ghost_at(ghost& ghost, cell *w, const transmatrix& V, ghostmoment& p) {
dynamicval<charstyle> x(getcs(), ghost.cs);
if(ghost.cs.charid == -1) {
dynamicval<bool> pc(peace::on, true);
2019-01-17 13:11:12 +00:00
drawMonsterType(eMonster(ghost.cs.uicolor), w, V, ghost.cs.dresscolor, uchar_to_frac(p.footphase));
return;
}
2019-01-17 13:11:12 +00:00
drawMonsterType(moPlayer, w, V, 0, uchar_to_frac(p.footphase));
}
bool ghost_finished(ghost& ghost) {
auto p = std::find_if(ghost.history.begin(), ghost.history.end(), [] (const ghostmoment gm) { return gm.step > ticks - race_start_tick;} );
return p == ghost.history.end();
}
ghostmoment& get_ghostmoment(ghost& ghost) {
auto p = std::find_if(ghost.history.begin(), ghost.history.end(), [] (const ghostmoment gm) { return gm.step > ticks - race_start_tick;} );
if(p == ghost.history.end()) p--, p->footphase = 0;
return *p;
}
void draw_ghost(ghost& ghost) {
auto& p = get_ghostmoment(ghost);
cell *w = rti[p.where_id].c;
if(!gmatrix.count(w)) return;
draw_ghost_at(ghost, w, get_ghostmoment_matrix(p), p);
}
transmatrix racerel(ld rel) {
int bsize = vid.fsize * 2;
return atscreenpos(bsize, vid.yres - bsize - rel * (vid.yres - bsize*2) / 100, bsize) * spin(M_PI/2);
}
int get_percentage(cell *c) {
return min(get_info(c).completion * 100 / (isize(track) - DROP), 100);
}
int get_percentage(int i) {
return get_percentage(shmup::pc[i]->base);
}
void draw_ghost_state(ghost& ghost) {
auto& p = get_ghostmoment(ghost);
cell *w = rti[p.where_id].c;
ld result = ghost_finished(ghost) ? 100 : get_percentage(w);
draw_ghost_at(ghost, w, racerel(result), p);
}
void drawStats() {
if(!racing::on) return;
2019-02-27 12:34:52 +00:00
if(DIM == 3) return;
2019-01-17 13:11:12 +00:00
initquickqueue();
int bsize = vid.fsize * 2;
for(int y: {bsize, vid.yres - bsize}) {
curvepoint(atscreenpos(bsize, y, bsize) * C0);
curvepoint(atscreenpos(bsize/2, y, bsize) * C0);
curvepoint(atscreenpos(bsize*3/2, y, bsize) * C0);
curvepoint(atscreenpos(bsize, y, bsize) * C0);
}
queuecurve(0xFFFFFFFF, 0, PPR::ZERO);
for(auto& ghost: ghostset()[specialland]) draw_ghost_state(ghost);
for(auto& ghost: oghostset()[specialland]) draw_ghost_state(ghost);
for(int i=0; i<multi::players; i++) {
dynamicval<int> d(multi::cpid, i);
drawMonsterType(moPlayer, shmup::pc[i]->base, racerel(race_finish_tick[i] ? 100 : get_percentage(i)), 0xFFFFFFC0, shmup::pc[i]->footphase);
}
quickqueue();
}
void markers() {
if(!racing::on) return;
2019-02-27 12:34:52 +00:00
if(guiding && DIM == 2) for(int i=0; i<multi::players; i++) {
2019-01-07 03:53:09 +00:00
shmup::monster *m = shmup::pc[i];
if(!m) continue;
for(int j=0; j<5; j++)
queueline(m->pat * xpush0(j), m->pat * xpush0(j+1), multi::scs[i].uicolor, 2);
}
2019-02-27 12:34:52 +00:00
if(racing::player_relative || racing::standard_centering || DIM == 3) {
using namespace racing;
cell *goal = NULL;
for(cell *c: track) if(inscreenrange(c)) goal = c;
if(!goal) return;
hyperpoint H = tC0(ggmatrix(goal));
if(invalid_point(H)) return;
queuechr(H, 2*vid.fsize, 'X', 0x10100 * int(128 + 100 * sintick(150)));
2018-12-04 20:17:57 +00:00
queuestr(H, vid.fsize,
2019-02-27 14:53:07 +00:00
#if CAP_CRYSTAL
2018-12-04 20:17:57 +00:00
(geometry == gCrystal && !crystal::pure()) ? fts(crystal::space_distance(cwt.at, track.back())) :
2019-02-27 14:53:07 +00:00
#endif
2018-12-04 20:17:57 +00:00
its(celldistance(cwt.at, track.back())), 0x10101 * int(128 - 100 * sintick(150)));
2018-12-23 13:30:18 +00:00
addauraspecial(H, 0xFFD500, 0);
}
int ghosts_left = ghosts_to_show;
2019-01-07 03:56:06 +00:00
for(auto& ghost: ghostset()[specialland]) {
if(!ghosts_left) break;
ghosts_left--;
draw_ghost(ghost);
}
2018-11-25 22:39:47 +00:00
2019-01-07 03:56:06 +00:00
for(auto& ghost: oghostset()[specialland])
draw_ghost(ghost);
2018-11-25 22:39:47 +00:00
if(gmatrix.count(track[0])) {
for(ld z=-start_line_width; z<=start_line_width; z+=0.1)
curvepoint(ggmatrix(track[0]) * straight * parabolic1(z) * C0);
queuecurve(0xFFFFFFFF, 0, PPR::BFLOOR);
}
}
2018-12-23 12:10:46 +00:00
void add_debug(cell *c) {
if(racing::on && racing::rti_id[c]) {
auto& r = racing::get_info(c);
dialog::addSelItem("from_track", its(r.from_track), 0);
dialog::addSelItem("from_start", its(r.from_start), 0);
dialog::addSelItem("from_goal", its(r.from_goal), 0);
dialog::addSelItem("completion", its(r.completion), 0);
}
}
}
2018-11-17 18:30:50 +00:00
}