|
|
@@ -1,3 +1,20 @@
|
|
|
+/*
|
|
|
+ * 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 <https://www.gnu.org/licenses/>.
|
|
|
+ */
|
|
|
+
|
|
|
#include <stdio.h>
|
|
|
#include <string.h>
|
|
|
#include "../optimize.h"
|
|
|
@@ -88,12 +105,9 @@ static int generate_filename(Optimizer_Data *data, char *ext, char *filename){
|
|
|
(data->unit->name[i] >= 'a' && data->unit->name[i] <= 'z')
|
|
|
|| (data->unit->name[i] >= 'A' && data->unit->name[i] <= 'Z')
|
|
|
|| (data->unit->name[i] >= '0' && data->unit->name[i] <= '9')
|
|
|
- ){
|
|
|
+ )
|
|
|
unit_name[i] = data->unit->name[i];
|
|
|
- }
|
|
|
- else{
|
|
|
- unit_name[i] = '-';
|
|
|
- }
|
|
|
+ else unit_name[i] = '-';
|
|
|
}
|
|
|
unit_name[i] = '\0';
|
|
|
strcpy(filename, data->unit->id);
|
|
|
@@ -113,10 +127,7 @@ static int diff_string(
|
|
|
int diff = modified - current;
|
|
|
int i;
|
|
|
if (diff == 0){
|
|
|
- for (i = 0; i < padding + 1; i ++){
|
|
|
- string[i] = ' ';
|
|
|
- }
|
|
|
-
|
|
|
+ for (i = 0; i < padding + 1; i ++) string[i] = ' ';
|
|
|
string[i] = '\0';
|
|
|
}
|
|
|
else if (diff > 0){
|
|
|
@@ -165,9 +176,8 @@ extern int output(Optimizer_Data *data){
|
|
|
}
|
|
|
}
|
|
|
else if (format == OUTPUT_JSON){
|
|
|
- if (output == OUTPUT_SCREEN){
|
|
|
+ if (output == OUTPUT_SCREEN)
|
|
|
return print_json(data, stdout, MAX_RESULTS_SCREEN_JSON);
|
|
|
- }
|
|
|
else if (output == OUTPUT_FILE){
|
|
|
char filename[128];
|
|
|
generate_filename(data, "json", filename);
|
|
|
@@ -206,10 +216,8 @@ extern void output_summary(Optimizer_Data *data){
|
|
|
);
|
|
|
printf(" | %*s | ", -37, data->unit->name);
|
|
|
for (int i = 0; i < MAX_SETS; i ++){
|
|
|
- if (data->filters->sets[i] != 0){
|
|
|
- //printf(" %d ", data->filters->sets[i]);
|
|
|
+ if (data->filters->sets[i] != 0)
|
|
|
printf(" %s ", SET_NAMES[data->filters->sets[i]]);
|
|
|
- }
|
|
|
else break;
|
|
|
}
|
|
|
printf("\n");
|
|
|
@@ -297,13 +305,9 @@ static int print_human(
|
|
|
int i;
|
|
|
if (order == ORDER_ASC){
|
|
|
i = data->total_results - 1;
|
|
|
- if (i > max){
|
|
|
- i = max;
|
|
|
- }
|
|
|
- }
|
|
|
- else{
|
|
|
- i = 0;
|
|
|
+ if (i > max) i = max;
|
|
|
}
|
|
|
+ else i = 0;
|
|
|
|
|
|
while (1){
|
|
|
if (i != data->total_results){
|
|
|
@@ -340,9 +344,7 @@ static int print_human(
|
|
|
result.rating, "\033[39m"
|
|
|
);
|
|
|
}
|
|
|
- else{
|
|
|
- sprintf(rating, "%d", result.rating);
|
|
|
- }
|
|
|
+ else sprintf(rating, "%d", result.rating);
|
|
|
fprintf(
|
|
|
target,
|
|
|
"| DEF: | %*u | %*u | %s | Rating: %s \n",
|
|
|
@@ -398,9 +400,7 @@ static int print_human(
|
|
|
"------------------------------------------\n"
|
|
|
);
|
|
|
char lines[10][190];
|
|
|
- for (int l = 0; l < 10; l ++){
|
|
|
- strcpy(lines[l], "");
|
|
|
- }
|
|
|
+ for (int l = 0; l < 10; l ++) strcpy(lines[l], "");
|
|
|
|
|
|
// Print all the runes in the result
|
|
|
int start_pos = 0;
|
|
|
@@ -449,9 +449,8 @@ static int print_human(
|
|
|
strcat(lines[1], rune_id);
|
|
|
|
|
|
// Row 2, rune location
|
|
|
- if (strlen(sqlite3_column_text(stmt_rune, 0)) == 0){
|
|
|
+ if (strlen(sqlite3_column_text(stmt_rune, 0)) == 0)
|
|
|
strcat(lines[2], "| In inventory");
|
|
|
- }
|
|
|
else{
|
|
|
if (strcmp(sqlite3_column_text(stmt_rune, 0), unit->id) == 0){
|
|
|
if (color == TRUE)
|
|
|
@@ -477,9 +476,7 @@ static int print_human(
|
|
|
strncpy(tmp + 2, sqlite3_column_text(stmt_rune, 0), 11);
|
|
|
}
|
|
|
sqlite3_finalize(stmt_unit);
|
|
|
- while (strlen(tmp) < 13){
|
|
|
- strcat(tmp, " ");
|
|
|
- }
|
|
|
+ while (strlen(tmp) < 13) strcat(tmp, " ");
|
|
|
strcat(lines[2], "|");
|
|
|
strcat(lines[2], tmp);
|
|
|
}
|
|
|
@@ -503,18 +500,11 @@ static int print_human(
|
|
|
if (
|
|
|
stat == 2 || stat == 4 || stat == 6 || stat == 8
|
|
|
|| stat == 9 || stat == 10 || stat == 11
|
|
|
- ){
|
|
|
+ )
|
|
|
percentile = TRUE;
|
|
|
- }
|
|
|
- else{
|
|
|
- percentile = FALSE;
|
|
|
- }
|
|
|
- if (slot == 0){
|
|
|
- has_innate = TRUE;
|
|
|
- }
|
|
|
- else if (slot > total_subs){
|
|
|
- total_subs = slot;
|
|
|
- }
|
|
|
+ else percentile = FALSE;
|
|
|
+ if (0 == slot) has_innate = TRUE;
|
|
|
+ else if (slot > total_subs) total_subs = slot;
|
|
|
// Stat name and value.
|
|
|
sprintf(
|
|
|
tmp, "%3s%4d%c",
|
|
|
@@ -546,36 +536,28 @@ static int print_human(
|
|
|
strcat(tmp, tmp2);
|
|
|
if (color == TRUE) strcat(tmp, "\033[39m");
|
|
|
}
|
|
|
- else{
|
|
|
- strcat(tmp, " ");
|
|
|
- }
|
|
|
+ else strcat(tmp, " ");
|
|
|
strcat(lines[slot + 4], "|");
|
|
|
strcat(lines[slot + 4], tmp);
|
|
|
}
|
|
|
sqlite3_finalize(stmt_stat);
|
|
|
// It the rune has no innate stat, add empty space.
|
|
|
- if (has_innate == FALSE){
|
|
|
- strcat(lines[4], "| ");
|
|
|
- }
|
|
|
+ if (has_innate == FALSE) strcat(lines[4], "| ");
|
|
|
// Add empty space for each subsstat the runes doeesn't have.
|
|
|
- for (; total_subs < 4; total_subs ++){
|
|
|
+ for (; total_subs < 4; total_subs ++)
|
|
|
strcat(lines[5 + total_subs], "| ");
|
|
|
- }
|
|
|
+
|
|
|
// Row 9: Efficiency
|
|
|
sprintf(
|
|
|
tmp, "|E: %2.1f/%2.1fX", sqlite3_column_double(stmt_rune, 5),
|
|
|
sqlite3_column_double(stmt_rune, 6)
|
|
|
);
|
|
|
strcat(lines[9], tmp);
|
|
|
-
|
|
|
sqlite3_finalize(stmt_rune);
|
|
|
}
|
|
|
for (int l = 3; l < 10; l ++){
|
|
|
- for (int x = 0; x < strlen(lines[l]); x ++){
|
|
|
- if (lines[l][x] == 'X'){
|
|
|
- lines[l][x] = '%';
|
|
|
- }
|
|
|
- }
|
|
|
+ for (int x = 0; x < strlen(lines[l]); x ++)
|
|
|
+ if (lines[l][x] == 'X') lines[l][x] = '%';
|
|
|
}
|
|
|
|
|
|
for (int l = 0; l < 10; l ++){
|
|
|
@@ -591,15 +573,11 @@ static int print_human(
|
|
|
total_printed ++;
|
|
|
// Break conditions
|
|
|
if (order == ORDER_ASC){
|
|
|
- if (0 == i){
|
|
|
- break;
|
|
|
- }
|
|
|
+ if (0 == i) break;
|
|
|
i --;
|
|
|
}
|
|
|
else{
|
|
|
- if (i == data->total_results - 1 || i == max - 1){
|
|
|
- break;
|
|
|
- }
|
|
|
+ if (i == data->total_results - 1 || i == max - 1) break;
|
|
|
i ++;
|
|
|
}
|
|
|
}
|
|
|
@@ -654,9 +632,7 @@ static int print_json(Optimizer_Data *data, FILE *target, unsigned int max){
|
|
|
strcat(json, "]},");
|
|
|
|
|
|
// If last result, remove last comma
|
|
|
- if (i == data->total_results - 1 || i == max - 1){
|
|
|
- json[strlen(json) - 1] = 0;
|
|
|
- }
|
|
|
+ if (i == data->total_results - 1 || i == max - 1) json[strlen(json) - 1] = 0;
|
|
|
total_printed ++;
|
|
|
fprintf(target, json);
|
|
|
}
|