#include "game/stats.h"
#include <string.h>

static GameStats *s_active = NULL;

void stats_reset(GameStats *s) {
    memset(s, 0, sizeof(GameStats));
}

void stats_update_score(GameStats *s) {
    int score = s->enemies_killed * 100
              + s->levels_completed * 500
              - s->deaths * 200
              - (int)s->time_elapsed;
    s->score = score > 0 ? score : 0;
}

void stats_set_active(GameStats *s) { s_active = s; }
GameStats *stats_get_active(void)   { return s_active; }

void stats_record_kill(void)          { if (s_active) s_active->enemies_killed++; }
void stats_record_death(void)         { if (s_active) s_active->deaths++; }
void stats_record_shot_fired(void)    { if (s_active) s_active->shots_fired++; }
void stats_record_shot_hit(void)      { if (s_active) s_active->shots_hit++; }
void stats_record_dash(void)          { if (s_active) s_active->dashes_used++; }
void stats_record_jump(void)          { if (s_active) s_active->jumps++; }
void stats_record_pickup(void)        { if (s_active) s_active->pickups_collected++; }
void stats_record_damage_taken(int n) { if (s_active) s_active->damage_taken += n; }
void stats_record_damage_dealt(int n) { if (s_active) s_active->damage_dealt += n; }
