From e0212b14957201819964a397c3667985549c3efb Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Mon, 7 Jan 2019 04:56:06 +0100 Subject: [PATCH] more official racers --- graph.cpp | 3 +- racing.cpp | 101 +++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 81 insertions(+), 23 deletions(-) diff --git a/graph.cpp b/graph.cpp index 051fba0a..7b947756 100644 --- a/graph.cpp +++ b/graph.cpp @@ -1068,7 +1068,8 @@ bool drawMonsterType(eMonster m, cell *where, const transmatrix& V, color_t col, ShadowV(V, shPBody); const transmatrix VBS = VBODY * otherbodyparts(V, darkena(0xC0C0A0, 0, 0xC0), m, footphase); queuepoly(VBS, shPBody, darkena(0xC0C0A0, 0, 0xC0)); - queuepoly(VBS, shPSword, darkena(0xFFFF00, 0, 0xFF)); + if(!racing::on) + queuepoly(VBS, shPSword, darkena(0xFFFF00, 0, 0xFF)); queuepoly(VBS, shKnightArmor, darkena(0xD0D0D0, 1, 0xFF)); color_t col; if(!eubinary && where && where->master->alt) diff --git a/racing.cpp b/racing.cpp index 6f254e1c..b7f4695b 100644 --- a/racing.cpp +++ b/racing.cpp @@ -75,9 +75,13 @@ struct ghost { vector history; }; -map, map > > race_ghosts; +using raceset = map>; +map, raceset> race_ghosts; -map, map > > official_race_ghosts; +map, 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())]; } array, MAXPLAYER> current_history; @@ -120,18 +124,53 @@ void hwrite(hstream& hs, const ghost& gh) { hwrite(hs, gh.cs, gh.result, gh.timestamp, gh.checksum, gh.history); } - bool read_ghosts(string seed, int mcode) { if(seed == "OFFICIAL" && mcode == 2) { + auto &ors = oghostset(); + raceset crs; + if(1) { fhstream f("vizier.data", "rb"); if(f.f) { f.get(); - hread(f, official_race_ghosts[{seed, mcode}]); - for(auto& p: official_race_ghosts) - for(auto& v: p.second) - for(auto& w: v.second) + hread(f, crs); + for(auto& p: crs) for(auto& w: p.second) { w.cs.charid = -1, w.cs.uicolor = moVizier, w.cs.dresscolor = 0xC00000; + ors[p.first].push_back(w); + } + } + } + + if(1) { + fhstream f("hedgehog.data", "rb"); + if(f.f) { + f.get(); + hread(f, crs); + for(auto& p: crs) for(auto& w: p.second) { + w.cs.charid = -1, w.cs.uicolor = moHedge, w.cs.dresscolor = 0x00C000; + ors[p.first].push_back(w); + } + } + } + + if(1) { + fhstream f("knight.data", "rb"); + if(f.f) { + f.get(); + hread(f, crs); + for(auto& p: crs) for(auto& w: p.second) { + w.cs.charid = -1, w.cs.uicolor = moKnight, w.cs.dresscolor = 0x0000D0; + ors[p.first].push_back(w); + } + } + } + + for(auto p: ors) { + println(hlog, linf[p.first].name); + auto& v = p.second; + sort(v.begin(), v.end(), [] (const ghost &g1, const ghost &g2) { return g1.result < g2.result; }); + for(auto gh: v) + println(hlog, " ", racetimeformat(gh.result), " : ", format("%08X", gh.checksum), " = ", minf[gh.cs.uicolor].name); } } @@ -140,7 +179,7 @@ bool read_ghosts(string seed, int mcode) { fhstream f(fname, "rb"); if(!f.f) return false; f.get (); - hread(f, race_ghosts[{seed, mcode}]); + hread(f, ghostset()); return true; } @@ -149,9 +188,15 @@ void write_ghosts(string seed, int mcode) { 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); - hwrite(f, race_ghosts[{seed, mcode}]); + hwrite(f, ghostset()); } +transmatrix get_ghostmoment(ghostmoment& p) { + 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; + } + void fix_cave(cell *c) { int v = 0; // if(c->wall == waCavewall) v++; @@ -216,7 +261,7 @@ void generate_track() { TWIDTH = getDistLimit() - 1; - if(race_ghosts[{track_code, modecode()}].empty()) + if(ghostset().empty()) read_ghosts(track_code, modecode()); track.clear(); @@ -435,13 +480,25 @@ void generate_track() { for(int i=0; i forbidden; + for(auto& ghost: ghostset()[specialland]) + forbidden.push_back(get_ghostmoment(ghost.history[0])); + for(auto& ghost: oghostset()[specialland]) + forbidden.push_back(get_ghostmoment(ghost.history[0])); + for(int i=0; iat = straight * parabolic1(start_line_width * (rand() % 20000 - 10000) / 40000) * spin(rand() % 360); - who->base = s; + + for(int j=0; j<100; j++) { + who->at = straight * parabolic1(start_line_width * (rand() % 20000 - 10000) / 40000) * spin(rand() % 360); + 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; + } virtualRebase(who, true); } @@ -586,11 +643,11 @@ void generate_track() { track_ready = true; race_checksum = hrand(1000000); - auto& gh = race_ghosts[{track_code, modecode()}] [specialland]; + auto& gh = ghostset() [specialland]; int ngh = 0; for(int i=0; i>= 2; } - auto &subtrack = race_ghosts[{track_code, modecode()}] [specialland]; + auto &subtrack = ghostset() [specialland]; - subtrack.emplace_back(ghost{gcs, ticks - race_start_tick, race_checksum, time(NULL), current_history[current_player]}); - sort(subtrack.begin(), subtrack.end(), [] (const ghost &g1, const ghost &g2) { return g1.result > g2.result; }); + subtrack.emplace_back(ghost{gcs, result, race_checksum, time(NULL), current_history[current_player]}); + 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); if(ghosts_to_save > 0) @@ -1063,13 +1120,13 @@ void markers() { addauraspecial(H, 0xFFD500, 0); } int ghosts_left = ghosts_to_show; - for(auto& ghost: race_ghosts[{track_code, modecode()}][specialland]) { + for(auto& ghost: ghostset()[specialland]) { if(!ghosts_left) break; ghosts_left--; draw_ghost(ghost); } - for(auto& ghost: official_race_ghosts[{track_code, modecode()}][specialland]) + for(auto& ghost: oghostset()[specialland]) draw_ghost(ghost); if(gmatrix.count(track[0])) {