#include "untitled.h"



/* void equip_armor(Creature * player, Item * item); */



/*  ***********************************************************************
    * allocates and initializes a new creature                            *
    * [param] name  name of the creature                                  *
    * [returns] a pointer to the creature                                 *
    *           NULL if failure                                           *
    ***********************************************************************  */

Creature * create_creature ( const char * name, double time_to_live)
{
    Creature * creature = NULL;

    creature = malloc(sizeof(Creature));
    if (creature == NULL)
    {
        error("Failed to allocate memory for the player structure.", __FILE__, __LINE__);
        return NULL;
    };

    /* basic information */
    (void) strcpy(creature->name, name);
    creature->description[0] = '\0';
    creature->spawn_text->string[0] = '\0';
    creature->spawn_text->next = NULL;
    creature->death_text->string[0] = '\0';
    creature->death_text->next = NULL;
    creature->attack_text->string[0] = '\0';
    creature->attack_text->next = NULL;
    creature->type = CREATURE;
    creature->size = MEDIUM;
    creature->weight = 100.0;
    creature->location = NULL;
    creature->time_to_live = time_to_live;
    creature->time_alive = 0;

    /* attributes */
    creature->strength = 1;
    creature->dexterity = 1;
    creature->constitution = 1;
    creature->will = 1;
    creature->acuity = 1;
    creature->memory = 1;
    creature->charisma = 1;

    /* health */
    creature->max_endurance = (float) creature->constitution * 10;
    creature->endurance = creature->max_endurance;
    creature->scalp = 100;
    creature->forehead = 100;
    creature->left_ear = 100;
    creature->right_ear = 100;
    creature->left_eye = 100;
    creature->right_eye = 100;
    creature->nose = 100;
    creature->lips = 100;
    creature->left_cheek = 100;
    creature->right_cheek = 100;
    creature->chin = 100;
    creature->jaw = 100;
    creature->neck = 100;
    creature->left_shoulder = 100;
    creature->right_shoulder = 100;
    creature->chest = 100;
    creature->back = 100;
    creature->butt = 100;
    creature->abdomen = 100;
    creature->groin = 100;
    creature->left_bicep = 100;
    creature->right_bicep = 100;
    creature->left_forearm = 100;
    creature->right_forearm = 100;
    creature->left_wrist = 100;
    creature->right_wrist = 100;
    creature->left_elbow = 100;
    creature->right_elbow = 100;
    creature->left_dorsal = 100;
    creature->right_dorsal = 100;
    creature->left_palm = 100;
    creature->right_palm = 100;
    creature->left_fingers = 100;
    creature->right_fingers = 100;
    creature->left_thumb = 100;
    creature->right_thumb = 100;
    creature->left_thigh = 100;
    creature->right_thigh = 100;
    creature->left_calf = 100;
    creature->right_calf = 100;
    creature->left_knee = 100;
    creature->right_knee = 100;
    creature->left_shin = 100;
    creature->right_shin = 100;
    creature->left_ankle = 100;
    creature->right_ankle = 100;
    creature->left_heel = 100;
    creature->right_heel = 100;
    creature->left_midfoot = 100;
    creature->right_midfoot = 100;
    creature->left_toes = 100;
    creature->right_toes = 100;
    creature->vitality = calculate_vitality(creature);

    /* items */
    creature->right_held = NULL;
    creature->left_held = NULL;
    creature->inventory = NULL;
    creature->equipment = NULL;

    /* combat */
    creature->balance = 0;
    creature->engaged_enemies = 0;

    /* skills */
    creature->unarmed = 0;
    creature->one_handed_slash = 0;
    creature->one_handed_blunt = 0;
    creature->one_handed_piercing = 0;
    creature->two_handed_slash = 0;
    creature->two_handed_blunt = 0;
    creature->two_handed_piercing = 0;
    creature->polearms = 0;
    creature->staves = 0;
    creature->throwing = 0;
    creature->bows = 0;
    creature->crossbows = 0;
    creature->bash = 0;
    creature->backstab = 0;
    creature->dual_wielding = 0;
    creature->double_attack = 0;
    creature->disarm = 0;
    creature->unarmored_resistance = 0;
    creature->cloth_armor = 0;
    creature->leather_armor = 0;
    creature->mail_armor = 0;
    creature->wooden_armor = 0;
    creature->bone_armor = 0;
    creature->plate_armor = 0;
    creature->evasion = 0;
    creature->blocking = 0;
    creature->parrying = 0;
    creature->multiple_opponents = 0;
    creature->foraging = 0;
    creature->perception = 0;
    creature->stealing = 0;
    creature->climbing = 0;
    creature->swimming = 0;
    creature->skinning = 0;
    creature->hiding = 0;
    creature->sneaking = 0;
    creature->tracking = 0;
    creature->lockpicking = 0;
    creature->disarming = 0;
    creature->bandaging = 0;
    creature->bartering = 0;
    creature->appraisal = 0;
    creature->alchemy = 0;
    creature->baking = 0;
    creature->brewing = 0;
    creature->carving = 0;
    creature->fishing = 0;
    creature->fletching = 0;
    creature->jewelcraft = 0;
    creature->pottery = 0;
    creature->smithing = 0;
    creature->tailoring = 0;

    creature->is_attacking = FALSE;

    creature->next = NULL;

    return creature;
}


Item * create_armor ( const char * name, const char * description )
{
    Item * armor = NULL;

    armor = malloc(sizeof(Item));
    if (armor == NULL)
    {
        error("Failed to allocate memory for the equipment structure.", __FILE__, __LINE__);
        return NULL;
    };

    (void) strcpy(armor->name, name);
    (void) strcpy(armor->description, description);
    armor->type = MAIL;
    armor->size = MEDIUM;
    armor->weight = 20;
    armor->quality = 100;
    armor->condition.head = 0;
    armor->condition.ears = 0;
    armor->condition.face = 0;
    armor->condition.jaw = 0;
    armor->condition.neck = 0;
    armor->condition.left_shoulder = 100;
    armor->condition.right_shoulder = 100;
    armor->condition.chest = 100;
    armor->condition.abdomen = 100;
    armor->condition.groin = 0;
    armor->condition.back = 100;
    armor->condition.buttocks = 0;
    armor->condition.left_bicep = 100;
    armor->condition.right_bicep = 100;
    armor->condition.left_forearm = 0;
    armor->condition.right_forearm = 0;
    armor->condition.left_wrist = 0;
    armor->condition.right_wrist = 0;
    armor->condition.left_hand = 0;
    armor->condition.right_hand = 0;
    armor->condition.left_leg = 0;
    armor->condition.right_leg = 0;
    armor->condition.left_foot = 0;
    armor->condition.right_foot = 0;
    armor->location = TORSO;
    armor->occupance = 3;
    armor->contents = NULL;
    armor->protection = 25;
    armor->absorption = 15;
    armor->hindrance = 45;
    armor->slashing_damage = 0;
    armor->blunt_damage = 0;
    armor->piercing_damage = 0;
    armor->next = NULL;

    return armor;
}



Room * create_room ( const char * name, const char * description )
{
    Room * room = NULL;

    room = malloc(sizeof(Room));
    if (room == NULL)
    {
        error("Failed to allocate memory for the equipment structure.", __FILE__, __LINE__);
        return NULL;
    };

    (void) strcpy(room->name, name);
    (void) strcpy(room->description, description);
    room->adjacent_rooms = NULL;
    room->spawns = NULL;
    room->spawn_limit = 3;
    room->number_of_spawns = 0;
    room->players = NULL;
    room->creatures = NULL;
    room->items = NULL;
    room->usable_objects = NULL;

    room->next = NULL;

    return room;
}



Spawn_Group * create_spawn_group ( const char * name, short max_spawns, double time_to_spawn, double time_to_live, float spawn_probability )
{
    Spawn_Group * spawn = NULL;

    spawn = malloc(sizeof(Spawn_Group));
    if (spawn == NULL)
    {
        error("", __FILE__, __LINE__);
        return NULL;
    };

    (void) strcpy(spawn->creature_name, name);
    spawn->current_num_spawns = 0;
    spawn->max_spawns = max_spawns;
    spawn->time_to_spawn = time_to_spawn;
    spawn->time_to_live = time_to_live;
    spawn->spawn_timer = 0.0;
    spawn->spawn_probability = spawn_probability;
    spawn->next = NULL;

    return spawn;
}



Creature * find_creature_in_room ( char * name, Room * room, short * ordinal )
{
    Creature * player = NULL;
    Creature * creature = NULL;

    if (room == NULL)
        return NULL;

    name[0] = tolower(name[0]);

    player = room->players;
    while (player != NULL)
    {
        if (strncmp(name, player->name, strlen(name)) == 0 && *ordinal > 1)
            (*ordinal)--;
        else if (strncmp(name, player->name, strlen(name)) == 0 && *ordinal == 1)
            return player;

        player = player->next;
    };

    creature = room->creatures;
    while (creature != NULL)
    {
        if (strncmp(name, creature->name, strlen(name)) == 0 && *ordinal > 1)
            (*ordinal)--;
        else if (strncmp(name, creature->name, strlen(name)) == 0 && *ordinal == 1)
            return creature;

        creature = creature->next;
    };

    return NULL;
}

Item * find_item_in_room ( char * name, Room * room, short * ordinal )
{
    Item * item = NULL;

    if (room == NULL)
        return NULL;

    name[0] = tolower(name[0]);

    item = room->items;
    while (item != NULL)
    {
        if (strncmp(name, item->name, strlen(name)) == 0 && *ordinal > 1)
            (*ordinal)--;
        else if (strncmp(name, item->name, strlen(name)) == 0 && *ordinal == 1)
            return item;

        item = item->next;
    };

    item = room->usable_objects;
    while (item != NULL)
    {
        if (strncmp(name, item->name, strlen(name)) == 0 && *ordinal > 1)
            (*ordinal)--;
        else if (strncmp(name, item->name, strlen(name)) == 0 && *ordinal == 1)
            return item;

        item = item->next;
    };

    return NULL;
}

Item * find_item_in_hands ( char * name, Creature * creature, short * ordinal )
{
    if (creature == NULL)
        return NULL;

    name[0] = tolower(name[0]);

    if (creature->right_held != NULL)
    {
        if (strncmp(name, creature->right_held->name, strlen(name)) == 0 && *ordinal > 1)
            (*ordinal)--;
        else if (strncmp(name, creature->right_held->name, strlen(name)) == 0 && *ordinal == 1)
            return creature->right_held;
    };

    if (creature->left_held != NULL)
    {
        if (strncmp(name, creature->left_held->name, strlen(name)) == 0 && *ordinal > 1)
            (*ordinal)--;
        else if (strncmp(name, creature->left_held->name, strlen(name)) == 0 && *ordinal == 1)
            return creature->left_held;
    };

    return NULL;
}

Item * find_item_in_inventory ( char * name, Item * inventory, short * ordinal )
{
    Item * item = NULL;

    if (inventory == NULL)
        return NULL;

    name[0] = tolower(name[0]);

    item = inventory;
    while (item != NULL)
    {
        Item * item_in_container = NULL;

        if (strncmp(name, item->name, strlen(name)) == 0 && *ordinal > 1)
            (*ordinal)--;
        else if (strncmp(name, item->name, strlen(name)) == 0 && *ordinal == 1)
            return item;

        item_in_container = item->contents;
        while (item_in_container != NULL)
        {
            if (strncmp(name, item_in_container->name, strlen(name)) == 0 && *ordinal > 1)
                (*ordinal)--;
            else if (strncmp(name, item_in_container->name, strlen(name)) == 0 && *ordinal == 1)
                return item_in_container;

            item_in_container = item_in_container->next;
        };

        item = item->next;
    };

    return NULL;
}



short determine_ordinal ( char ** string )
{
    if (strncmp(*string, "first ", 6) == 0)
    {
        *string = *string + 6;
        return 1;
    }
    else if (strncmp(*string, "other ", 6) == 0)
    {
        *string = *string + 6;
        return 2;
    }
    else if (strncmp(*string, "second ", 7) == 0)
    {
        *string = *string + 7;
        return 2;
    }
    else if (strncmp(*string, "third ", 6) == 0)
    {
        *string = *string + 6;
        return 3;
    }
    else if (strncmp(*string, "fourth ", 7) == 0)
    {
        *string = *string + 7;
        return 4;
    }
    else if (strncmp(*string, "fifth ", 6) == 0)
    {
        *string = *string + 6;
        return 5;
    }
    else if (strncmp(*string, "sixth ", 6) == 0)
    {
        string = string + 6;
        return 6;
    }
    else if (strncmp(*string, "seventh ", 8) == 0)
    {
        string = string + 8;
        return 7;
    }
    else if (strncmp(*string, "eighth ", 7) == 0)
    {
        string = string + 7;
        return 8;
    }
    else if (strncmp(*string, "ninth ", 6) == 0)
    {
        string = string + 6;
        return 9;
    }
    else if (strncmp(*string, "tenth ", 6) == 0)
    {
        string = string + 6;
        return 10;
    }
    else
        return 1;

    return 1;
}



float calculate_vitality ( Creature * creature )
{
    double vitality = 100.0f;

    /* Note: 52 body parts */
    vitality -= -.5218015182 * creature->scalp + 52.18015446;
    vitality -= -.5218015182 * creature->forehead + 52.18015446;
    vitality -= -.5218015182 * creature->left_ear + 52.18015446;
    vitality -= -.5218015182 * creature->right_ear + 52.18015446;
    vitality -= -.5218015182 * creature->left_eye + 52.18015446;
    vitality -= -.5218015182 * creature->right_eye + 52.18015446;
    vitality -= -.5218015182 * creature->nose + 52.18015446;
    vitality -= -.5218015182 * creature->lips + 52.18015446;
    vitality -= -.5218015182 * creature->left_cheek + 52.18015446;
    vitality -= -.5218015182 * creature->right_cheek + 52.18015446;
    vitality -= -.5218015182 * creature->chin + 52.18015446;
    vitality -= -.5218015182 * creature->jaw + 52.18015446;
    vitality -= -.5218015182 * creature->neck + 52.18015446;
    vitality -= -.5218015182 * creature->left_shoulder + 52.18015446;
    vitality -= -.5218015182 * creature->right_shoulder + 52.18015446;
    vitality -= -.5218015182 * creature->chest + 52.18015446;
    vitality -= -.5218015182 * creature->back + 52.18015446;
    vitality -= -.5218015182 * creature->butt + 52.18015446;
    vitality -= -.5218015182 * creature->abdomen + 52.18015446;
    vitality -= -.5218015182 * creature->groin + 52.18015446;
    vitality -= -.5218015182 * creature->left_bicep + 52.18015446;
    vitality -= -.5218015182 * creature->right_bicep + 52.18015446;
    vitality -= -.5218015182 * creature->left_forearm + 52.18015446;
    vitality -= -.5218015182 * creature->right_forearm + 52.18015446;
    vitality -= -.5218015182 * creature->left_wrist + 52.18015446;
    vitality -= -.5218015182 * creature->right_wrist + 52.18015446;
    vitality -= -.5218015182 * creature->left_elbow + 52.18015446;
    vitality -= -.5218015182 * creature->right_elbow + 52.18015446;
    vitality -= -.5218015182 * creature->left_dorsal + 52.18015446;
    vitality -= -.5218015182 * creature->right_dorsal + 52.18015446;
    vitality -= -.5218015182 * creature->left_palm + 52.18015446;
    vitality -= -.5218015182 * creature->right_palm + 52.18015446;
    vitality -= -.5218015182 * creature->left_fingers + 52.18015446;
    vitality -= -.5218015182 * creature->right_fingers + 52.18015446;
    vitality -= -.5218015182 * creature->left_thumb + 52.18015446;
    vitality -= -.5218015182 * creature->right_thumb + 52.18015446;
    vitality -= -.5218015182 * creature->left_thigh + 52.18015446;
    vitality -= -.5218015182 * creature->right_thigh + 52.18015446;
    vitality -= -.5218015182 * creature->left_calf + 52.18015446;
    vitality -= -.5218015182 * creature->right_calf + 52.18015446;
    vitality -= -.5218015182 * creature->left_knee + 52.18015446;
    vitality -= -.5218015182 * creature->right_knee + 52.18015446;
    vitality -= -.5218015182 * creature->left_shin + 52.18015446;
    vitality -= -.5218015182 * creature->right_shin + 52.18015446;
    vitality -= -.5218015182 * creature->left_ankle + 52.18015446;
    vitality -= -.5218015182 * creature->right_ankle + 52.18015446;
    vitality -= -.5218015182 * creature->left_heel + 52.18015446;
    vitality -= -.5218015182 * creature->right_heel + 52.18015446;
    vitality -= -.5218015182 * creature->left_midfoot + 52.18015446;
    vitality -= -.5218015182 * creature->right_midfoot + 52.18015446;
    vitality -= -.5218015182 * creature->left_toes + 52.18015446;
    vitality -= -.5218015182 * creature->right_toes + 52.18015446;

    /* constitution increases the player's vitality */
    vitality *= .02 * creature->constitution + 1;

    if (vitality < 0)
        return 0;

    if (vitality  > 100)
        return 100;

    /* TODO: also need to apply endurance? to vitality */

    return vitality;

    /* Note:  Stupid vitality formula

    vitality = creature->scalp + creature->forehead + creature->left_ear + creature->right_ear + creature->left_eye + creature->right_eye
             + creature->nose + creature->lips + creature->left_cheek + creature->right_cheek + creature->chin + creature->jaw
             + creature->neck + creature->left_shoulder + creature->right_shoulder + creature->chest + creature->back + creature->butt
             + creature->abdomen + creature->groin + creature->left_bicep + creature->left_forearm + creature->left_wrist
             + creature->left_elbow + creature->right_bicep + creature->right_forearm + creature->right_wrist + creature->right_elbow
             + creature->left_dorsal + creature->left_palm + creature->left_fingers + creature->left_thumb + creature->right_dorsal
             + creature->right_palm + creature->right_fingers + creature->right_thumb + creature->left_thigh + creature->left_calf
             + creature->left_knee + creature->left_shin + creature->right_thigh + creature->right_calf + creature->right_knee
             + creature->right_shin + creature->left_ankle + creature->left_heel + creature->left_midfoot + creature->left_toes
             + creature->right_ankle + creature->right_heel + creature->right_midfoot + creature->right_toes;
    vitality /= 52.0; */
}

void display_health ( HWND window, Creature * creature )
{
    float fatigue = 0.0f;
    int number_injured_body_parts = 0, current_displayed_injuries = 0;
    BOOL update = FALSE;

    /* calculate and display the creature's vitality */
    creature->vitality = calculate_vitality(creature);
    output(window, "  [DEBUG] actual vitality: %lf\r\n", creature->vitality);
    if (creature->type == PLAYER)
        output(window, "You are ");
    else
        output(window, "It is ");
    if (creature->vitality <= 0)
        output(window, "dead.");
    else if (creature->vitality > 0 && creature->vitality <= 10)
        output(window, "at death's door.");
    else if (creature->vitality > 10 && creature->vitality <= 20)
        output(window, "in extremely bad shape.");
    else if (creature->vitality > 20 && creature->vitality <= 30)
        output(window, "in very bad shape.");
    else if (creature->vitality > 30 && creature->vitality <= 40)
        output(window, "in bad shape.");
    else if (creature->vitality > 40 && creature->vitality <= 50)
        output(window, "extremely beat up.");
    else if (creature->vitality > 50 && creature->vitality <= 60)
        output(window, "very beat up.");
    else if (creature->vitality > 60 && creature->vitality <= 70)
        output(window, "beat up.");
    else if (creature->vitality > 70 && creature->vitality <= 80)
        output(window, "battered.");
    else if (creature->vitality > 80 && creature->vitality <= 90)
        output(window, "somewhat battered.");
    else if (creature->vitality > 90 && creature->vitality < 100)
        output(window, "slightly battered.");
    else if (creature->vitality == 100)
        output(window, "at full health.");
    else if (creature->vitality > 100)
        output(window, "in superb health.");
    output(window, "\r\n");

    /* calculate and display the creature's endurance */
    if (creature->max_endurance == 0)
        fatigue = 0;
    else
        fatigue = creature->endurance / creature->max_endurance * 100.0f;
    if (creature->type == PLAYER)
        output(window, "You are ");
    else
        output(window, "It is ");
    if (fatigue == 0)
        output(window, "completely exhausted and unable to move.");
    else if (fatigue > 0 && fatigue <= 10)
        output(window, "completely exhausted.");
    else if (fatigue > 10 && fatigue <= 20)
        output(window, "on the verge of complete exhaustion.");
    else if (fatigue > 20 && fatigue <= 30)
        output(window, "extremely fatigued.");
    else if (fatigue > 30 && fatigue <= 40)
        output(window, "extremely tired.");
    else if (fatigue > 40 && fatigue <= 50)
        output(window, "very fatigued.");
    else if (fatigue > 50 && fatigue <= 60)
        output(window, "very tired.");
    else if (fatigue > 60 && fatigue <= 70)
        output(window, "fatigued.");
    else if (fatigue > 70 && fatigue <= 80)
        output(window, "tired.");
    else if (fatigue > 80 && fatigue <= 90)
        output(window, "somewhat tired.");
    else if (fatigue > 90 && fatigue < 100)
        output(window, "slightly fatigued.");
    else if (fatigue == 100)
        output(window, "full of energy.");
    output(window, "\r\n");

    number_injured_body_parts = get_number_of_injured_body_parts(creature);
    update = display_body_part_health(window, creature, "scalp", creature->scalp, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "forehead", creature->forehead, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left ear", creature->left_ear, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right ear", creature->right_ear, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left eye", creature->left_eye, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right eye", creature->right_eye, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "nose", creature->nose, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "lips", creature->lips, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left cheek", creature->left_cheek, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right cheek", creature->right_cheek, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "chin", creature->chin, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "jaw", creature->jaw, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "neck", creature->neck, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left shoulder", creature->left_shoulder, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right shoulder", creature->right_shoulder, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "chest", creature->chest, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "back", creature->back, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "butt", creature->butt, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "abdomen", creature->abdomen, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "groin", creature->groin, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left bicep", creature->left_bicep, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right bicep", creature->right_bicep, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left forearm", creature->left_forearm, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right forearm", creature->right_forearm, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left wrist", creature->left_wrist, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right wrist", creature->right_wrist, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left elbow", creature->left_elbow, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right elbow", creature->right_elbow, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left hand", creature->left_dorsal, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right hand", creature->right_dorsal, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left palm", creature->left_palm, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right palm", creature->right_palm, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left fingers", creature->left_fingers, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right fingers", creature->right_fingers, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left thumb", creature->left_thumb, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right thumb", creature->right_thumb, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left thigh", creature->left_thigh, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right thigh", creature->right_thigh, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left calf", creature->left_calf, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right calf", creature->right_calf, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left kneecap", creature->left_knee, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right kneecap", creature->right_knee, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left shin", creature->left_shin, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right shin", creature->right_shin, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left ankle", creature->left_ankle, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right ankle", creature->right_ankle, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left heel", creature->left_heel, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right heel", creature->right_heel, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left foot", creature->left_midfoot, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right foot", creature->right_midfoot, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "left toes", creature->left_toes, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
    update = display_body_part_health(window, creature, "right toes", creature->right_toes, current_displayed_injuries, number_injured_body_parts);
    if (update == TRUE)
        current_displayed_injuries++;
}

BOOL display_body_part_health ( HWND window, Creature * creature, const char * body_part, float value, int current_displayed_injuries, int number_injured_body_parts )
{
    if (value == 100)
        return FALSE;

    /* left hand fingers */
    if (creature->type == PLAYER && current_displayed_injuries == 0 && strcmp(body_part, "left fingers") == 0)
        output(window, "The fingers on your left hand ");
    else if (creature->type != PLAYER && current_displayed_injuries == 0 && strcmp(body_part, "left fingers") == 0)
        output(window, "The %s's fingers on its left hand ");
    else if (creature->type == PLAYER && current_displayed_injuries != 0 && strcmp(body_part, "left fingers") == 0)
        output(window, "the fingers on your left hand ");
    else if (creature->type != PLAYER && current_displayed_injuries != 0 && strcmp(body_part, "left fingers") == 0)
        output(window, "the fingers on its left hand ");
    /* right hand fingers */
    else if (creature->type == PLAYER && current_displayed_injuries == 0 && strcmp(body_part, "right fingers") == 0)
        output(window, "The fingers on your right hand ");
    else if (creature->type != PLAYER && current_displayed_injuries == 0 && strcmp(body_part, "right fingers") == 0)
        output(window, "The %s's fingers on its right hand ");
    else if (creature->type == PLAYER && current_displayed_injuries != 0 && strcmp(body_part, "right fingers") == 0)
        output(window, "the fingers on your right hand ");
    else if (creature->type != PLAYER && current_displayed_injuries != 0 && strcmp(body_part, "right fingers") == 0)
        output(window, "the fingers on its right hand ");
    /* left toes */
    else if (creature->type == PLAYER && current_displayed_injuries == 0 && strcmp(body_part, "left toes") == 0)
        output(window, "The toes on your left toes ");
    else if (creature->type != PLAYER && current_displayed_injuries == 0 && strcmp(body_part, "left toes") == 0)
        output(window, "The %s's toes on its left toes ");
    else if (creature->type == PLAYER && current_displayed_injuries != 0 && strcmp(body_part, "left toes") == 0)
        output(window, "the toes on your left toes ");
    else if (creature->type != PLAYER && current_displayed_injuries != 0 && strcmp(body_part, "left toes") == 0)
        output(window, "the toes on its left toes ");
    /* right toes */
    else if (creature->type == PLAYER && current_displayed_injuries == 0 && strcmp(body_part, "right toes") == 0)
        output(window, "The toes on your right toes ");
    else if (creature->type != PLAYER && current_displayed_injuries == 0 && strcmp(body_part, "right toes") == 0)
        output(window, "The %s's toes on its right toes ");
    else if (creature->type == PLAYER && current_displayed_injuries != 0 && strcmp(body_part, "right toes") == 0)
        output(window, "the toes on your right toes ");
    else if (creature->type != PLAYER && current_displayed_injuries != 0 && strcmp(body_part, "right toes") == 0)
        output(window, "the toes on its right toes ");

    /* general */
    else if (creature->type == PLAYER && current_displayed_injuries == 0)
        output(window, "Your %s ", body_part);
    else if (creature->type == PLAYER && current_displayed_injuries != 0)
        output(window, "your %s ", body_part);
    else if (creature->type != PLAYER && current_displayed_injuries == 0)
        output(window, "A %s's %s ", creature->name, body_part);
    else if (creature->type != PLAYER && current_displayed_injuries != 0)
        output(window, "its %s ", body_part);

    /* plural */
    if (strcmp(body_part, "lips") == 0 || strcmp(body_part, "left toes") == 0 || strcmp(body_part, "right toes") == 0
     || strcmp(body_part, "left fingers") == 0 || strcmp(body_part, "right fingers") == 0)
        output(window, "are ");
    else
        output(window, "is ");

    /* status */
    if (value == 0)
        output(window, "completely useless");
    else if (value > 0 && value <= 20)
        output(window, "nearly useless");
    else if (value > 20 && value <= 30)
        output(window, "torn apart");
    else if (value > 30 && value <= 50)
        output(window, "severely bleeding");
    else if (value > 50 && value <= 70)
        output(window, "bleeding");
    else if (value > 70 && value <= 80)
        output(window, "cut");
    else if (value > 80 && value <= 90)
        output(window, "bruised");
    else if (value > 90 && value < 100)
        output(window, "scratched");

    if (current_displayed_injuries == number_injured_body_parts - 1)
        output(window , ".");
    else if (current_displayed_injuries == number_injured_body_parts - 2)
        output(window, " and ");
    else if (current_displayed_injuries < number_injured_body_parts - 1)
        output(window, ", ");

    return TRUE;
}

int get_number_of_injured_body_parts ( Creature * creature )
{
    int count = 0;

    if (creature->scalp < 100)
        count++;
    if (creature->forehead < 100)
        count++;
    if (creature->left_ear < 100)
        count++;
    if (creature->right_ear < 100)
        count++;
    if (creature->left_eye < 100)
        count++;
    if (creature->right_eye < 100)
        count++;
    if (creature->nose < 100)
        count++;
    if (creature->lips < 100)
        count++;
    if (creature->left_cheek < 100)
        count++;
    if (creature->right_cheek < 100)
        count++;
    if (creature->chin < 100)
        count++;
    if (creature->jaw < 100)
        count++;
    if (creature->neck < 100)
        count++;
    if (creature->left_shoulder < 100)
        count++;
    if (creature->right_shoulder < 100)
        count++;
    if (creature->chest < 100)
        count++;
    if (creature->back < 100)
        count++;
    if (creature->butt < 100)
        count++;
    if (creature->abdomen < 100)
        count++;
    if (creature->groin < 100)
        count++;
    if (creature->left_bicep < 100)
        count++;
    if (creature->right_bicep < 100)
        count++;
    if (creature->left_forearm < 100)
        count++;
    if (creature->right_forearm < 100)
        count++;
    if (creature->left_wrist < 100)
        count++;
    if (creature->right_wrist < 100)
        count++;
    if (creature->left_elbow < 100)
        count++;
    if (creature->right_elbow < 100)
        count++;
    if (creature->left_dorsal < 100)
        count++;
    if (creature->right_dorsal < 100)
        count++;
    if (creature->left_palm < 100)
        count++;
    if (creature->right_palm < 100)
        count++;
    if (creature->left_fingers < 100)
        count++;
    if (creature->right_fingers < 100)
        count++;
    if (creature->left_thumb < 100)
        count++;
    if (creature->right_thumb < 100)
        count++;
    if (creature->left_thigh < 100)
        count++;
    if (creature->right_thigh < 100)
        count++;
    if (creature->left_calf < 100)
        count++;
    if (creature->right_calf < 100)
        count++;
    if (creature->left_knee < 100)
        count++;
    if (creature->right_knee < 100)
        count++;
    if (creature->left_shin < 100)
        count++;
    if (creature->right_shin < 100)
        count++;
    if (creature->left_ankle < 100)
        count++;
    if (creature->right_ankle < 100)
        count++;
    if (creature->left_heel < 100)
        count++;
    if (creature->right_heel < 100)
        count++;
    if (creature->left_midfoot < 100)
        count++;
    if (creature->right_midfoot < 100)
        count++;
    if (creature->left_toes < 100)
        count++;
    if (creature->right_toes < 100)
        count++;

    return count;
}

float get_weapon_skill ( Creature * creature, BOOL is_right_hand )
{
    float weapon_skill = 0.0f;
    short weapon_type = 0;

    if (is_right_hand == TRUE)
    {
        if (creature->right_held == NULL)
            return creature->unarmed;
        else
            weapon_type = creature->right_held->type;
    }
    else
    {
        if (creature->left_held == NULL)
            return creature->unarmed;
        else
            weapon_type = creature->left_held->type;
    };

    switch (weapon_type)
    {
        case UNARMED:
            weapon_skill = creature->unarmed;
            break;
        case ONE_HANDED_SLASH:
            weapon_skill = creature->one_handed_slash;
            break;
        case ONE_HANDED_BLUNT:
            weapon_skill = creature->one_handed_blunt;
            break;
        case ONE_HANDED_PIERCING:
            weapon_skill = creature->one_handed_piercing;
            break;
        case TWO_HANDED_SLASH:
            weapon_skill = creature->two_handed_slash;
            break;
        case TWO_HANDED_BLUNT:
            weapon_skill = creature->two_handed_blunt;
            break;
        case TWO_HANDED_PIERCING:
            weapon_skill = creature->two_handed_piercing;
            break;
        case POLEARM:
            weapon_skill = creature->polearms;
            break;
        case STAFF:
            weapon_skill = creature->staves;
            break;
        case THROWING:
            weapon_skill = creature->throwing;
            break;
        case BOW:
            weapon_skill = creature->bows;
            break;
        case CROSSBOW:
            weapon_skill = creature->crossbows;
            break;
        default:
            weapon_skill = creature->unarmed;
            break;
    };

    return weapon_skill;
}

