/* * This file is part of RuneOptimizer. * * RuneOptimizer is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) * any later version. * * RuneOptimizer is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * RuneOptimizer. If not, see . */ /** * @file update_efficiency.c * * Implementation of {@link update_efficiency}. * * This file implements the funciton {@link update_efficiency} declared in * {@link update.h}. */ #include #include #include "../error/error.h" #include "../db/db.h" #include "../runeoptimizer.h" extern int update_efficiency(char *id, float *efficiency, float *max_efficiency){ *efficiency = 0.0f; *max_efficiency = 0.0f; float eff[5] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; sqlite3_stmt *stmt_rune; sqlite3_stmt *stmt_stats; char *parameters[1] = {id}; db_query( &stmt_rune, "SELECT stars, level FROM runes WHERE id = ?", parameters ); if (SQLITE_ROW != sqlite3_step(stmt_rune)) { fprintf(stderr, "Rune not found: %s\n", sqlite3_errmsg(db)); sqlite3_finalize(stmt_rune); return(ERROR_DB_SELECT_RUNE); } int stars = sqlite3_column_int(stmt_rune, 0); int level = sqlite3_column_int(stmt_rune, 1); db_query( &stmt_stats, "SELECT slot, stat, value FROM rune_stats WHERE rune = ? AND slot != -1", parameters ); // Calculate efficiency for each slot. // Main slot is excluded from the calculation. while (SQLITE_ROW == sqlite3_step(stmt_stats)){ int slot = sqlite3_column_int(stmt_stats, 0); int stat = sqlite3_column_int(stmt_stats, 1); int value = sqlite3_column_int(stmt_stats, 2); int max_roll_value = STAT_ROLL_MAX[stat][stars]; eff[slot] += (((float) value) / ((float) max_roll_value)); } sqlite3_finalize(stmt_stats); sqlite3_finalize(stmt_rune); // Sum each slot efficiency. // Each roll contributes only 1/9 to the total efficiency. for (int i = 0; i < 5; i ++){ eff[i] = eff[i] / 9.0f; *efficiency += eff[i]; } // Calculate max efficiency. For each power up remaining, add 1/9. *max_efficiency = *efficiency; if (level < 12) *max_efficiency += (1.0f / 9.0f); if (level < 9) *max_efficiency += (1.0f / 9.0f); if (level < 6) *max_efficiency += (1.0f / 9.0f); if (level < 3) *max_efficiency += (1.0f / 9.0f); // Multiply by 100 to get a percent value *efficiency *= 100.0f; *max_efficiency *= 100.0f; return(SUCCESS); }