1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-20 11:54:48 +00:00

rulegen:: apply arb::convert, and imrpoved generation

This commit is contained in:
Zeno Rogue 2021-07-29 16:15:40 +02:00
parent c996805533
commit 4a0f688673
2 changed files with 18 additions and 15 deletions

View File

@ -343,6 +343,7 @@ EX void initcells() {
#if CAP_CRYSTAL #if CAP_CRYSTAL
else if(cryst) currentmap = crystal::new_map(); else if(cryst) currentmap = crystal::new_map();
#endif #endif
else if(arb::in() && rulegen::known()) currentmap = rulegen::new_hrmap_rulegen();
else if(arb::in()) currentmap = arb::new_map(); else if(arb::in()) currentmap = arb::new_map();
#if CAP_ARCM #if CAP_ARCM
else if(arcm::in()) currentmap = arcm::new_map(); else if(arcm::in()) currentmap = arcm::new_map();

View File

@ -1240,8 +1240,12 @@ EX void generate_rules() {
delete_tmap(); delete_tmap();
if(!arb::in()) if(!arb::in()) try {
throw rulegen_surrender("rulegen algorithm works only on arb tessellations"); arb::convert::convert();
}
catch(hr_exception& e) {
throw rulegen_surrender("conversion failure");
}
prepare_around_radius = 1; prepare_around_radius = 1;
@ -1504,21 +1508,16 @@ EX int get_state(cell *c) {
return c->master->fieldval; return c->master->fieldval;
} }
EX void restart_game_on(hrmap *m) { string rules_known_for = "unknown";
stop_game();
int a = addHook(hooks_newmap, 0, [m] { return m;});
start_game();
delHook(hooks_newmap, a);
}
string rules_known_for;
string rule_status; string rule_status;
EX bool known() {
return rules_known_for == arb::current.name;
}
bool prepare_rules() { bool prepare_rules() {
if(rules_known_for == arb::current.name) return true; if(known()) return true;
try { try {
if(!arb::in())
throw rulegen_failure("rulegen in wrong tessellation");
generate_rules(); generate_rules();
rules_known_for = arb::current.name; rules_known_for = arb::current.name;
rule_status = XLAT("rules generated successfully"); rule_status = XLAT("rules generated successfully");
@ -1549,8 +1548,11 @@ int args() {
cleanup(); cleanup();
else if(argis("-rulegen-play")) { else if(argis("-rulegen-play")) {
PHASEFROM(3); PHASEFROM(3);
if(prepare_rules()) if(prepare_rules()) {
restart_game_on(new hrmap_rulegen); stop_game();
set_geometry(gArbitrary);
start_game();
}
} }
else return 1; else return 1;
return 0; return 0;