void GameInstSet::deserialize(GameState* gs, SerializeBuffer& serializer) { serializer.read_int(grid_w); serializer.read_int(grid_h); //Resize and clear unit_grid.resize(grid_w * grid_h); clear(); int amnt; serializer.read_int(amnt); serializer.read_int(next_id); for (int i = 0; i < amnt; i++) { InstType type; int id; serializer.read_int(type); serializer.read_int(id); printf("Deserializing id=%d\n", id); GameInst* inst = get_instance(id); bool has_inst = inst != NULL; if (!has_inst) { inst = from_inst_type(type); inst->deserialize(gs, serializer); inst->last_x = inst->x; inst->last_y = inst->y; inst->id = id; add_instance(inst, inst->id); } else { safe_deserialize(inst, gs, serializer); } LANARTS_ASSERT( serializer_equals_read(serializer, inst->integrity_hash())); } }
unsigned int GameInstSet::hash() const { unsigned int hash = 0xbabdabe; std::vector<GameInst*> as_vector = to_vector(); for (int i = 0; i < as_vector.size(); i++) { GameInst* inst = as_vector[i]; if (!dynamic_cast<AnimatedInst*>(inst)) { hash ^= inst->integrity_hash(); hash ^= hash * 31337; //Ad hoc hashing yay } } return hash; }
static void process_level_hash(GameState* gs, GameLevelState* level, SerializeBuffer& sb, bool isw) { if (level->id() == -1) return; std::vector<GameInst*> instances = level->game_inst_set().to_vector(); for (int i = 0; i < instances.size(); i++) { GameInst* inst = instances[i]; if (!dynamic_cast<AnimatedInst*>(inst)) { write_or_assert_hash(sb, inst->integrity_hash(), isw); } } //compare magic number marker write_or_assert_hash(sb, 0xABCDFFFF, isw); write_or_assert_hash(sb, level->game_inst_set().hash(), isw); }
void GameInstSet::serialize(GameState* gs, SerializeBuffer& serializer) { serializer.write_int(grid_w); serializer.write_int(grid_h); serializer.write_int(size()); serializer.write_int(next_id); DepthMap::const_iterator it = depthlist_map.end(); for (int ind = 0; it != depthlist_map.begin();) { --it; InstanceState* state = it->second.start_of_list; while (state) { GameInst* inst = state->inst; serializer.write_int(get_inst_type(inst)); serializer.write_int(inst->id); inst->serialize(gs, serializer); serializer.write_int(inst->integrity_hash()); state = state->next_same_depth; } } }
/* Helper method for drawing basic stat information*/ static void draw_player_base_stats(GameState* gs, PlayerInst* player_inst, int x, int y, int width) { ClassStats& class_stats = player_inst->class_stats(); CoreStats& core = player_inst->effective_stats().core; int x_interval = width / 2; int y_interval = 15; gs->font().drawf(ldraw::DrawOptions(COL_WHITE).origin(ldraw::CENTER), Pos(x - 10 + x_interval, 15), "Level %d", class_stats.xplevel); // y += y_interval; Pos p1(x, y), p2(x + x_interval, y); gs->font().drawf(COL_WHITE, Pos(x, y), "Kills %d", player_inst->score_stats().kills); if (gs->game_settings().regen_on_death) { gs->font().drawf(COL_PALE_RED, Pos(x + x_interval, y), "Deaths %d", player_inst->score_stats().deaths); } else { gs->font().draw(COL_PALE_BLUE, Pos(x + x_interval, y), "Hardcore"); } p1.y += y_interval; p2.y += y_interval; gs->font().drawf(COL_WHITE, p1, "%s", gs->get_level()->label().c_str()); gs->font().drawf(COL_GOLD, p2, "Gold %d", player_inst->gold()); p1.y += y_interval; p2.y += y_interval; gs->font().drawf(COL_MUTED_GREEN, p1, "Strength %d", core.strength); gs->font().drawf(COL_MUTED_GREEN, p2, "Magic %d", core.magic); p1.y += y_interval; p2.y += y_interval; gs->font().drawf(COL_MUTED_GREEN, p1, "Defence %d", core.defence); gs->font().drawf(COL_MUTED_GREEN, p2, "Will %d", core.willpower); p1.y += y_interval; p2.y += y_interval; // Draw hashes if in network debug mode if (gs->game_settings().network_debug_mode) { // Draw level hash gs->font().drawf(COL_MUTED_GREEN, p1, "Hash 0x%X", gs->get_level()->game_inst_set().hash()); p1.y += y_interval; // Draw player hashes for (int i = 0; i < gs->player_data().all_players().size(); i++) { unsigned int hash = gs->player_data().all_players()[i].player()->integrity_hash(); gs->font().drawf(COL_MUTED_GREEN, p1, "P%d 0x%X", i + 1, hash); p1.y += y_interval; } // Draw monster hashes (note, takes up a lot of screen space) for (int i = 0; i < gs->monster_controller().monster_ids().size(); i++) { GameInst* inst = gs->get_instance( gs->monster_controller().monster_ids()[i]); if (inst) { gs->font().drawf(COL_MUTED_GREEN, Pos(0, i * y_interval), "M%d 0x%X", i + 1, inst->integrity_hash()); } } } }