aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMosder <xmosder12@gmail.com>2026-07-20 15:39:23 +0200
committerMosder <xmosder12@gmail.com>2026-07-20 15:39:23 +0200
commite0bf82fe2af66ef55872569ae15733f70b4913d4 (patch)
tree2b9031c60a0be523a7a9539d27f2f2e8e503799b
parent5244cb20402b272c933788ae7adf94fe0e035def (diff)
feat: added parsing of normal items
-rw-r--r--analyzer/parser/fight_results.c76
-rw-r--r--analyzer/parser/fight_results.h10
-rw-r--r--analyzer/render.c23
-rw-r--r--csv/items.csv1
4 files changed, 88 insertions, 22 deletions
diff --git a/analyzer/parser/fight_results.c b/analyzer/parser/fight_results.c
index d7b185a..5cda649 100644
--- a/analyzer/parser/fight_results.c
+++ b/analyzer/parser/fight_results.c
@@ -11,10 +11,11 @@
void cleanup_fight_results(void *data) {
FightResults *fight_results = data;
for (size_t i = 0; i < fight_results->num_friendly; i++) {
- free(fight_results->friendly_results[i].name);
- free(fight_results->friendly_results[i].gear);
- free(fight_results->friendly_results[i].items);
- free(fight_results->friendly_results[i].drifs);
+ FriendlyResults friendly = fight_results->friendly_results[i];
+ free(friendly.name);
+ for (size_t j = 0; j < friendly.num_items; j++)
+ free(friendly.items[j]);
+ free(friendly.items);
}
for (size_t i = 0; i < fight_results->num_enemy; i++) {
free(fight_results->enemy_results[i].name);
@@ -86,6 +87,59 @@ char *get_item_name(int item_id) {
return item_id < id_to_item_name_len ? id_to_item_name[item_id] : "null";
}
+char **expand_items(char **items, size_t *items_capacity, size_t to_fit) {
+ while (*items_capacity < to_fit)
+ *items_capacity <<= 1;
+ return realloc(items, *items_capacity * sizeof(char *));
+}
+
+void add_gear(FriendlyResults *results, size_t *items_capacity, char *gear_str) {
+ if (strlen(gear_str) == 0)
+ return;
+
+ // TODO: parse
+ if (results->num_items >= *items_capacity)
+ results->items = expand_items(results->items, items_capacity, results->num_items + 1);
+
+ results->items[results->num_items++] = strdup(gear_str);
+}
+
+void add_drifs(FriendlyResults *results, size_t *items_capacity, char *drifs_str) {
+ if (strlen(drifs_str) == 0)
+ return;
+
+ // TODO: parse
+ if (results->num_items >= *items_capacity)
+ results->items = expand_items(results->items, items_capacity, results->num_items + 1);
+
+ results->items[results->num_items++] = strdup(drifs_str);
+}
+
+void add_items(FriendlyResults *results, size_t *items_capacity, char *items_str) {
+ if (strlen(items_str) == 0)
+ return;
+
+ char *items_separator;
+ do {
+ char buffer[SINGLE_ITEM_BUFFER_LEN];
+ items_separator = strstr(items_str, SEPARATOR_ITEMS);
+
+ int item_id, item_count;
+ sscanf(items_str, "%d,%d", &item_id, &item_count);
+ sprintf(buffer, "%dx %s", item_count, get_item_name(item_id));
+
+ // if there are still items - modify items_str pointer
+ if (items_separator)
+ items_str = items_separator + strlen(SEPARATOR_ITEMS);
+
+ // expand if needed
+ if (results->num_items >= *items_capacity)
+ results->items = expand_items(results->items, items_capacity, results->num_items + 1);
+
+ results->items[results->num_items++] = strdup(buffer);
+ } while (items_separator);
+}
+
char *get_saturation_type(int saturation_id) {
return saturation_id < id_to_saturation_type_len ? id_to_saturation_type[saturation_id] : "null";
}
@@ -97,16 +151,18 @@ FriendlyResults parse_to_friendly(EntityResults entity_results) {
results.name = strdup(entity_results.name);
results.exp = entity_results.exp;
results.gold = entity_results.gold;
- // TODO: parse that to more readable format
- results.gear = strdup(entity_results.gear);
- // TODO: parse that to more readable format, determine types from ids
- results.items = strdup(entity_results.items);
results.level = entity_results.level;
results.psycho = entity_results.psycho;
- // TODO: parse that to more readable format
- results.drifs = strdup(entity_results.drifs);
results.splinters = entity_results.splinters;
+ // create items array and add to it gear, drifs and items
+ results.num_items = 0;
+ results.items = malloc(INIT_ITEMS_CAPACITY * sizeof(char *));
+ size_t items_cap = INIT_ITEMS_CAPACITY;
+ add_gear(&results, &items_cap, entity_results.gear);
+ add_drifs(&results, &items_cap, entity_results.drifs);
+ add_items(&results, &items_cap, entity_results.items);
+
results.saturation = 0;
if (strlen(entity_results.saturation) > 0) {
int saturation_id;
diff --git a/analyzer/parser/fight_results.h b/analyzer/parser/fight_results.h
index 17c2f05..ca45348 100644
--- a/analyzer/parser/fight_results.h
+++ b/analyzer/parser/fight_results.h
@@ -133,6 +133,11 @@ typedef struct {
} EntityResults;
#endif
+// items/gear/drifs fields parsing info
+#define INIT_ITEMS_CAPACITY 8
+#define SINGLE_ITEM_BUFFER_LEN 128
+#define SEPARATOR_ITEMS "[-]"
+
// values of field "team"
#define TEAM_FRIEND 1
#define TEAM_ENEMY 2
@@ -144,11 +149,10 @@ typedef struct {
char *name;
int exp;
int gold;
- char *gear;
- char *items;
+ char **items;
+ size_t num_items;
int level;
int psycho;
- char *drifs;
int splinters;
char *saturation_type;
int saturation;
diff --git a/analyzer/render.c b/analyzer/render.c
index 0c3df56..402fcb5 100644
--- a/analyzer/render.c
+++ b/analyzer/render.c
@@ -108,18 +108,23 @@ void print_player_rewards(FriendlyResults results) {
}
printf("\n");
- // TODO: change this when I parse the items etc. to a readable format
- // needs to utilize utf8_strlen, because right now utf8 characters mess the table up
- char big_buf[1024];
- sprintf(big_buf, "%s - %s - %s", results.items, results.gear, results.drifs);
- if (strlen(big_buf) > 6) {
+ if (results.num_items > 0) {
printf(TABLE_LINE_START);
print_center("ITEMS", COLOR_WHITE, TABLE_ITEMS_WIDTH, ' ');
- printf(TABLE_LINE_END "\n");
-
- for (size_t i = 0; i < strlen(big_buf); i += TABLE_ITEMS_WIDTH) {
- printf(TABLE_LINE_START "%-*.*s" TABLE_LINE_END "\n", (int)TABLE_ITEMS_WIDTH, (int)TABLE_ITEMS_WIDTH, big_buf + i);
+ printf(TABLE_LINE_END "\n" TABLE_LINE_START);
+
+ size_t line_len = 0;
+ for (size_t i = 0; i < results.num_items; i++) {
+ char *sep = i < results.num_items - 1 ? ", " : "";
+ size_t item_len = utf8_strlen(results.items[i]) + strlen(sep);
+ if (line_len + item_len > TABLE_ITEMS_WIDTH) {
+ printf("%*s" TABLE_LINE_END "\n" TABLE_LINE_START, (int)(TABLE_ITEMS_WIDTH - line_len), "");
+ line_len = 0;
+ }
+ printf("%s%s", results.items[i], sep);
+ line_len += item_len;
}
+ printf("%*s" TABLE_LINE_END "\n", (int)(TABLE_ITEMS_WIDTH - line_len), "");
}
}
diff --git a/csv/items.csv b/csv/items.csv
index de9a7ce..0265384 100644
--- a/csv/items.csv
+++ b/csv/items.csv
@@ -3,3 +3,4 @@ id,item_name
1219,Trop trwogi
986,KrysztaƂ czasu
703,Glif arcymistrzowski
+697,Glif bakalarski