1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-23 13:07:16 +00:00

bringris:: moved game-related values to gamedata struct

This commit is contained in:
Zeno Rogue 2024-11-17 13:40:40 +01:00
parent d2166aef08
commit 2575e768ac

View File

@ -95,7 +95,6 @@ int lti;
int bgeom = 0; int bgeom = 0;
int max_piece;
int default_max_piece; int default_max_piece;
bool rotate_allowed = false; bool rotate_allowed = false;
@ -118,9 +117,6 @@ vector<cell*> out_level;
map<cell*, int> center_distance; map<cell*, int> center_distance;
bool pro_game;
int well_size = 10;
int camera = 3; int camera = 3;
int facing_mod = 0; int facing_mod = 0;
@ -134,14 +130,21 @@ cellwalker at;
int move_started; int move_started;
int move_at; int move_at;
int completed;
int bricks, cubes;
ld score;
bool paused; bool paused;
bool explore; bool explore;
struct gamedata {
string bgeom_name;
string timerstart, timerend;
int max_piece;
bool pro_game;
ld score;
int bricks, completed, cubes, well_size, levelsize, seconds;
vector<string> lmap;
};
gamedata cur;
enum eState { enum eState {
tsPreGame, tsFalling, tsBetween, tsCollect, tsGameover tsPreGame, tsFalling, tsBetween, tsCollect, tsGameover
}; };
@ -325,7 +328,7 @@ vector<bgeometry> bgeoms = {
set_geometry(gProduct); set_geometry(gProduct);
default_max_piece = 5; default_max_piece = 5;
rotate_allowed = false; rotate_allowed = false;
well_size = 6; cur.well_size = 6;
}}, }},
{"orbifold", "one fifth of the giant", HYPERBOLIC | NONORIENTABLE | ORBIFOLD, [] { {"orbifold", "one fifth of the giant", HYPERBOLIC | NONORIENTABLE | ORBIFOLD, [] {
@ -370,9 +373,9 @@ void create_game();
void enable_bgeom() { void enable_bgeom() {
stop_game_and_switch_mode(rg::nothing); stop_game_and_switch_mode(rg::nothing);
well_size = 10; cur.well_size = 10;
bgeoms[bgeom].create(); bgeoms[bgeom].create();
max_piece = default_max_piece; cur.max_piece = default_max_piece;
start_game(); start_game();
create_game(); create_game();
state = tsPreGame; state = tsPreGame;
@ -612,7 +615,7 @@ void generate_shapes_rec(vector<cellwalker>& sofar, code_t& code, int cnt) {
} }
void generate_shapes(int cnt) { void generate_shapes(int cnt) {
vector<cellwalker> cws = { get_at(get_center(), -well_size - 1) }; vector<cellwalker> cws = { get_at(get_center(), -cur.well_size - 1) };
code_t co = {}; code_t co = {};
generate_shapes_rec(cws, co, cnt); generate_shapes_rec(cws, co, cnt);
} }
@ -648,7 +651,7 @@ color_t hipso[] = {
color_t get_hipso(ld y) { color_t get_hipso(ld y) {
y += 12; y += 12;
if(well_size <= 5) y *= 2; if(cur.well_size <= 5) y *= 2;
return hipso[gmod(y, 13)]; return hipso[gmod(y, 13)];
} }
@ -711,8 +714,8 @@ bool check_bshift(cellwalker c0, cellwalker c1) {
} }
ld current_move_time_limit() { ld current_move_time_limit() {
// return 50000 * pow(.9, completed) + 10000. / (1 + completed); // return 50000 * pow(.9, cur.completed) + 10000. / (1 + cur.completed);
return 3500 * pow(.995, completed * isize(level)); return 3500 * pow(.995, cur.completed * isize(level));
} }
int turn_animation = 500; int turn_animation = 500;
@ -748,7 +751,7 @@ void new_piece() {
if(well_center && true) { if(well_center && true) {
again: again:
if(get_where(at.at).first != well_center) { if(get_where(at.at).first != well_center) {
at.at = get_at(get_where(at.at).first, -well_size - 1); at.at = get_at(get_where(at.at).first, -cur.well_size - 1);
int d = center_distance[get_where(at.at).first]; int d = center_distance[get_where(at.at).first];
for(int i=0; i<4; i++) { for(int i=0; i<4; i++) {
auto mov = get_where(shift_block_target(i)).first; auto mov = get_where(shift_block_target(i)).first;
@ -761,14 +764,14 @@ void new_piece() {
} }
while(at.spin) rotate_block(1, true); while(at.spin) rotate_block(1, true);
} }
at.at = get_at(get_where(at.at).first, -well_size - 1); at.at = get_at(get_where(at.at).first, -cur.well_size - 1);
shape_id = next_shape_id; shape_id = next_shape_id;
next_shape_id = choose_piece(); next_shape_id = choose_piece();
if(shape_conflict(at)) { if(shape_conflict(at)) {
playSound(cwt.at, "die-bomberbird"); playSound(cwt.at, "die-bomberbird");
state = tsGameover; state = tsGameover;
if(pro_game && max_piece == default_max_piece) if(cur.pro_game && cur.max_piece == default_max_piece)
rv_leaderboard(bgeoms[bgeom].name, score); rv_leaderboard(bgeoms[bgeom].name, cur.score);
save(); save();
} }
else { else {
@ -785,7 +788,7 @@ void find_lines() {
by_level.clear(); by_level.clear();
// println(hlog, "Removing levels"); // println(hlog, "Removing levels");
for(int z=1; z<=well_size; z++) { for(int z=1; z<=cur.well_size; z++) {
int ct = 0; int ct = 0;
for(auto lev: level) { for(auto lev: level) {
cell *c = get_at(lev, -z); cell *c = get_at(lev, -z);
@ -798,7 +801,7 @@ void find_lines() {
int points = 0; int points = 0;
if(true) { if(true) {
for(int z=1; z<=well_size; z++) if(by_level[z-1] >= isize(level)) { for(int z=1; z<=cur.well_size; z++) if(by_level[z-1] >= isize(level)) {
points++; points++;
for(auto lev: level) { for(auto lev: level) {
cell *c = get_at(lev, -z); cell *c = get_at(lev, -z);
@ -808,7 +811,7 @@ void find_lines() {
} }
else { else {
// int lines_found = 0; // int lines_found = 0;
for(int z=1; z<=well_size; z++) { for(int z=1; z<=cur.well_size; z++) {
for(auto lev: level) for(int d=0; d<lev->type; d++) { for(auto lev: level) for(int d=0; d<lev->type; d++) {
cellwalker cw(get_at(lev, -z), d); cellwalker cw(get_at(lev, -z), d);
cellwalker cw0 = cw; cellwalker cw0 = cw;
@ -835,17 +838,17 @@ void find_lines() {
if(!to_disappear.empty()) { if(!to_disappear.empty()) {
move_at = ticks + collect_animation; move_at = ticks + collect_animation;
state = tsCollect; state = tsCollect;
score += 100000. * points * (points+1.) / current_move_time_limit(); cur.score += 100000. * points * (points+1.) / current_move_time_limit();
completed += points; cur.completed += points;
playSound(cwt.at, points == 1 ? "pickup-gold" : "orb-mind"); playSound(cwt.at, points == 1 ? "pickup-gold" : "orb-mind");
if(points == 4 && pro_game && max_piece == 4 && default_max_piece == 4) rv_achievement("BRINGRISFOUR"); if(points == 4 && cur.pro_game && cur.max_piece == 4 && default_max_piece == 4) rv_achievement("BRINGRISFOUR");
} }
} }
void disappear_lines() { void disappear_lines() {
for(auto lev: level) { for(auto lev: level) {
int nz = 1; int nz = 1;
for(int z=1; z<=well_size; z++) { for(int z=1; z<=cur.well_size; z++) {
cell *c1 = get_at(lev, -z); cell *c1 = get_at(lev, -z);
if(!to_disappear.count(c1)) { if(!to_disappear.count(c1)) {
cell *c0 = get_at(lev, -nz); cell *c0 = get_at(lev, -nz);
@ -872,11 +875,11 @@ void state_loop() {
void fallen() { void fallen() {
draw_shape(); draw_shape();
bricks++; cur.bricks++;
cubes += isize(piecelist[shape_id].code)+1; cur.cubes += isize(piecelist[shape_id].code)+1;
state = tsBetween; state = tsBetween;
playSound(cwt.at, "closegate"); playSound(cwt.at, "closegate");
score += 200000. / (current_move_time_limit() * 3 + ticks - move_started); cur.score += 200000. / (current_move_time_limit() * 3 + ticks - move_started);
} }
void drop() { void drop() {
@ -1141,7 +1144,7 @@ void draw_holes(int zlev) {
if(d) remove_shape(); if(d) remove_shape();
for(auto lev: level) { for(auto lev: level) {
bool covered = false; bool covered = false;
for(int z=well_size; z>=1; z--) { for(int z=cur.well_size; z>=1; z--) {
cell *c1 = get_at(lev, -z); cell *c1 = get_at(lev, -z);
if(c1->wall) covered = true; if(c1->wall) covered = true;
else if(covered) { else if(covered) {
@ -1214,7 +1217,7 @@ renderbuffer *next_buffer;
void draw_screen(int xstart, bool show_next) { void draw_screen(int xstart, bool show_next) {
int steps = camera_level - (-get_z(at.at)); int steps = camera_level - (-get_z(at.at));
if(state != tsFalling) steps = camera_level - (well_size + 1); if(state != tsFalling) steps = camera_level - (cur.well_size + 1);
#if CAP_VR #if CAP_VR
if(!explore) { if(!explore) {
@ -1254,7 +1257,7 @@ void draw_screen(int xstart, bool show_next) {
ld lv = -cgi.plevel * steps; ld lv = -cgi.plevel * steps;
shift_view(ztangent(lv)); shift_view(ztangent(lv));
rotate_view(cspin(1, 2, cur_ang)); rotate_view(cspin(1, 2, cur_ang));
shift_view(ztangent(cgi.plevel * (2 + max_piece))); shift_view(ztangent(cgi.plevel * (2 + cur.max_piece)));
centerover = ncenter; centerover = ncenter;
anims::moved(); anims::moved();
} }
@ -1277,7 +1280,7 @@ void draw_screen(int xstart, bool show_next) {
if(state == tsCollect && ticks >= move_at) if(state == tsCollect && ticks >= move_at)
disappear_lines(); disappear_lines();
if(ticks >= move_at && state == tsFalling && pro_game) { if(ticks >= move_at && state == tsFalling && cur.pro_game) {
auto_drop(); auto_drop();
} }
@ -1310,10 +1313,10 @@ void geometry_menu() {
} }
} }
dialog::addBreak(100); dialog::addBreak(100);
dialog::addSelItem("max piece", its(max_piece), 'M'); dialog::addSelItem("max piece", its(cur.max_piece), 'M');
dialog::add_action([] { dialog::add_action([] {
max_piece++; cur.max_piece++;
if(max_piece == 6) max_piece = 2; if(cur.max_piece == 6) cur.max_piece = 2;
create_game(); create_game();
state = tsPreGame; state = tsPreGame;
}); });
@ -1604,11 +1607,11 @@ void run() {
displaystr(xstart + vid.fsize, vid.yres - vid.fsize * 1, 0, vid.fsize, its(isize(level)), winf[waBarrier].color, 0); displaystr(xstart + vid.fsize, vid.yres - vid.fsize * 1, 0, vid.fsize, its(isize(level)), winf[waBarrier].color, 0);
if(state != tsPreGame) { if(state != tsPreGame) {
displaystr(xstart + vid.fsize, vid.yres - vid.fsize * 16, 0, vid.fsize, "LEVELS " + its(completed), winf[waBarrier].color, 0); displaystr(xstart + vid.fsize, vid.yres - vid.fsize * 16, 0, vid.fsize, "LEVELS " + its(cur.completed), winf[waBarrier].color, 0);
displaystr(xstart + vid.fsize, vid.yres - vid.fsize * 15, 0, vid.fsize, "BRICKS " + its(bricks), winf[waBarrier].color, 0); displaystr(xstart + vid.fsize, vid.yres - vid.fsize * 15, 0, vid.fsize, "BRICKS " + its(cur.bricks), winf[waBarrier].color, 0);
displaystr(xstart + vid.fsize, vid.yres - vid.fsize * 14, 0, vid.fsize, "CUBES " + its(cubes), winf[waBarrier].color, 0); displaystr(xstart + vid.fsize, vid.yres - vid.fsize * 14, 0, vid.fsize, "CUBES " + its(cur.cubes), winf[waBarrier].color, 0);
if(pro_game) if(cur.pro_game)
displaystr(xstart + vid.fsize, vid.yres - vid.fsize * 13, 0, vid.fsize, "SCORE " + fts(int(score)), winf[waBarrier].color, 0); displaystr(xstart + vid.fsize, vid.yres - vid.fsize * 13, 0, vid.fsize, "SCORE " + fts(int(cur.score)), winf[waBarrier].color, 0);
} }
if(show_next) { if(show_next) {
@ -1743,16 +1746,16 @@ void run() {
{"😀","😎","👽","🤖","😺","🎩","🎓","👑","💍","🐯","🦁","🐮","🐷","🐽","🐸","🐙","🐵","🐦","🐧","🐔","🐒","🙉","🙈","🐣","🐥","🐺","🐗","🐴","🦄","🐝","🐛","🐢","🦀","🦂","🕷","🐜","🐞","🐌","🐠","🐟","🐡","🐬","🐋","🐊","🐆","🐘","🐫","🐪","🐄","🐂","🐃","🐏","🐑","🐀","🐁","🐓","🦃","🐉","🐾","🐿","🐇","🐈","🐩","🐕","🐲","🌵","🍁","🌻","🌎","⭐️","⚡️","🔥","❄️","☔️","☂️","💧","🍏","🍎","🍐","🍋","🍌","🍉","🍇","🌶","🍅","🍍","🍑","🍈","🍓","🌽","🍠","🍯","🍞","🍗","🧀","🍖","🍤","🌯","🌮","🍝","🍕","🌭","🍟","🍔","⚽️","🎱","🏆","🎪","🎲","🎳","🚗","🚕","🚙","🏎","⛺️","","🕹","💾","☎️","","🔦","💡","💰","💎","🔨","💣","🔑","❤️","🔔"}; {"😀","😎","👽","🤖","😺","🎩","🎓","👑","💍","🐯","🦁","🐮","🐷","🐽","🐸","🐙","🐵","🐦","🐧","🐔","🐒","🙉","🙈","🐣","🐥","🐺","🐗","🐴","🦄","🐝","🐛","🐢","🦀","🦂","🕷","🐜","🐞","🐌","🐠","🐟","🐡","🐬","🐋","🐊","🐆","🐘","🐫","🐪","🐄","🐂","🐃","🐏","🐑","🐀","🐁","🐓","🦃","🐉","🐾","🐿","🐇","🐈","🐩","🐕","🐲","🌵","🍁","🌻","🌎","⭐️","⚡️","🔥","❄️","☔️","☂️","💧","🍏","🍎","🍐","🍋","🍌","🍉","🍇","🌶","🍅","🍍","🍑","🍈","🍓","🌽","🍠","🍯","🍞","🍗","🧀","🍖","🍤","🌯","🌮","🍝","🍕","🌭","🍟","🍔","⚽️","🎱","🏆","🎪","🎲","🎳","🚗","🚕","🚙","🏎","⛺️","","🕹","💾","☎️","","🔦","💡","💰","💎","🔨","💣","🔑","❤️","🔔"};
string out; string out;
if(pro_game) { if(cur.pro_game) {
out = "Got " + its(score) + " points for completing " + its(completed) + " levels in #Bringris!"; out = "Got " + its(cur.score) + " points for completing " + its(cur.completed) + " levels in #Bringris!";
} }
else if(completed) { else if(cur.completed) {
out = "Used " + its(bricks) + " blocks to complete " + its(completed) + " levels in #Bringris!"; out = "Used " + its(cur.bricks) + " blocks to complete " + its(cur.completed) + " levels in #Bringris!";
} }
else { else {
out = "Dropped " + its(bricks) + " blocks in #Bringris!"; out = "Dropped " + its(cur.bricks) + " blocks in #Bringris!";
} }
if(bgeom || max_piece != 4) out += " (" + bgeoms[bgeom].name + "/" + its(max_piece) + ")"; if(bgeom || cur.max_piece != 4) out += " (" + bgeoms[bgeom].name + "/" + its(cur.max_piece) + ")";
unsigned hash = time(NULL) / 600; unsigned hash = time(NULL) / 600;
for(char c: out) hash = 171 * hash + c; for(char c: out) hash = 171 * hash + c;
std::mt19937 invr; std::mt19937 invr;
@ -1780,7 +1783,7 @@ void run() {
start_new_game(); start_new_game();
paused = false; paused = false;
explore = false; explore = false;
pro_game = false; cur.pro_game = false;
playSound(cwt.at, "elementalgem"); playSound(cwt.at, "elementalgem");
} }
if(in_menu && sym == 's') { if(in_menu && sym == 's') {
@ -1790,7 +1793,7 @@ void run() {
start_new_game(); start_new_game();
paused = false; paused = false;
explore = false; explore = false;
pro_game = true; cur.pro_game = true;
playSound(cwt.at, "elementalgem"); playSound(cwt.at, "elementalgem");
} }
#if CAP_SHOT #if CAP_SHOT
@ -1900,7 +1903,7 @@ void start_new_game() {
c->landparam = (get_hipso(z) & 0xFCFCFC) >> 2; c->landparam = (get_hipso(z) & 0xFCFCFC) >> 2;
} }
at = get_at(get_center(), -well_size - 1); at = get_at(get_center(), -cur.well_size - 1);
next_shape_id = choose_piece(); next_shape_id = choose_piece();
state = tsBetween; state = tsBetween;
@ -1910,10 +1913,10 @@ void start_new_game() {
// reset_view(); // reset_view();
completed = 0; cur.completed = 0;
bricks = 0; cur.bricks = 0;
cubes = 0; cur.cubes = 0;
score = 0; cur.score = 0;
} }
void get_level() { void get_level() {
@ -2010,12 +2013,12 @@ void create_game() {
piecelist.clear(); piecelist.clear();
piecelist.reserve(2000); piecelist.reserve(2000);
seen_blocks.clear(); seen_blocks.clear();
for(int ps=1; ps<=max_piece; ps++) for(int ps=1; ps<=cur.max_piece; ps++)
generate_shapes(ps); generate_shapes(ps);
list_all(); list_all();
// println(hlog, "level size = ", isize(level)); // println(hlog, "level size = ", isize(level));
camera_level = well_size + max_piece + camera; camera_level = cur.well_size + cur.max_piece + camera;
playermoved = false; playermoved = false;
ray::max_iter_current() = solnil ? 600 : 200; ray::max_iter_current() = solnil ? 600 : 200;
@ -2145,29 +2148,45 @@ auto hook1=
}); });
#endif #endif
void save() { vector<gamedata> allsaves;
#if CAP_SAVE
fhstream f("bringris.save", "at"); void fill_gamedata() {
println(f, "Bringris ", BRINGRIS_VER); cur.bgeom_name = bgeoms[bgeom].name;
println(f, bgeoms[bgeom].name);
time_t timer; time_t timer;
timer = time(NULL); timer = time(NULL);
char sbuf[128]; strftime(sbuf, 128, "%c", localtime(&timerstart)); char buf[128];
char buf[128]; strftime(buf, 128, "%c", localtime(&timer)); strftime(buf, 128, "%c", localtime(&timerstart)); cur.timerstart = buf;
println(f, sbuf); strftime(buf, 128, "%c", localtime(&timer)); cur.timerend = buf;
println(f, buf); cur.levelsize = isize(level);
println(f, max_piece, " ", pro_game ? score : -1, " ", bricks, " ", completed, " ", cubes, " ", well_size, " ", isize(level), " ", int(timer - timerstart)); cur.seconds = int(timer - timerstart);
for(int z=0; z<=well_size; z++) { cur.lmap.clear();
for(int z=0; z<=cur.well_size; z++) {
string s; string s;
for(auto lev: level) { for(auto lev: level) {
cell *c = get_at(lev, -z); cell *c = get_at(lev, -z);
s += (c->wall ? '#' : '.'); s += (c->wall ? '#' : '.');
} }
println(f, s); cur.lmap.push_back(s);
} }
}
void save(const gamedata& sd) {
#if CAP_SAVE
fhstream f("bringris.save", "at");
println(f, "Bringris ", BRINGRIS_VER);
println(f, sd.bgeom_name);
println(f, sd.timerstart);
println(f, sd.timerend);
println(f, sd.max_piece, " ", sd.pro_game ? sd.score : -1, " ", sd.bricks, " ", sd.completed, " ", sd.cubes, " ", sd.well_size, " ", sd.levelsize, " ", sd.seconds);
for(auto& s: sd.lmap) println(f, s.c_str());
#endif #endif
} }
void save() {
fill_gamedata();
save(cur);
}
void load() { void load() {
} }