Quicker than I expected since I only worked on the code I am displaying, but here is the same code beautified for your perusal:
/**
* @brief Add a new wound to the actor in a random location.
* @param[in] target Who is injured
* @param[in] damage How much damage is being inflicted
*/
void G_ActorDamage (edict_t *target, const int damage)
{
wound_t *newWound;
int randomValue;
/**< Sanity check, don't add a wound if no damage was done. */
if(damage <= 0)
return;
newWound = malloc(sizeof(wound_t));
/**< First determine where the wound is */
randomValue = rand() % (WOUND_HEAD_PROBABILITY + WOUND_CHEST_PROBABILITY + WOUND_ARMS_PROBABILITY + WOUND_LEGS_PROBABILITY);
if(randomValue < WOUND_HEAD_PROBABILITY) {
newWound->location = WOUND_HEAD;
}
else if(randomValue < WOUND_HEAD_PROBABILITY + WOUND_CHEST_PROBABILITY) {
newWound->location = WOUND_CHEST;
}
else if(randomValue < WOUND_HEAD_PROBABILITY + WOUND_CHEST_PROBABILITY + WOUND_ARMS_PROBABILITY) {
newWound->location = WOUND_ARMS;
}
else if(randomValue < WOUND_HEAD_PROBABILITY + WOUND_CHEST_PROBABILITY + WOUND_ARMS_PROBABILITY + WOUND_LEGS_PROBABILITY) {
newWound->location = WOUND_LEGS;
}
/**< This should *never* happen, put out an error or something */
else {
/**< WOUND_LEGS is probably the highest enum value, so % by it. */
newWound->location %= WOUND_LEGS;
}
/**< Next determine if it is a wound */
if(damage < WOUND_MINIMUM_DAMAGE) {
newWound->affectSkill = 0;
newWound->treated = 1;
}
else {
newWound->affectSkill = 1;
newWound->treated = 0;
}
/**< Finally set the damage of the wound */
newWound->value = damage;
/**< The wound is created, just add it to the target now */
LIST_AddPointer(&target->chr.wounds, newWound);
/**< Subtract the damage from the current hit points. */
target->HP -= damage;
}
/**
* @brief Return the decrease in accuracy due to wounds for an actor.
* @param[in] target The injured actor we are calculating the decrease in accuracy for.
*/
int G_ActorAccuracyDecreaseByWounds (edict_t *target)
{
linkedList_t *woundList;
wound_t *wound;
int armWounds = 0, headWounds = 0, returnValue = 0;
/**< Calculate all arm wounds, we'll have to go through the wound linkedlist to count all arm wounds. */
woundList = target->chr.wounds;
while (woundList) {
wound = (wound_t *)woundList->data;
if ((wound->location == WOUND_ARMS) && wound->affectSkill) {
if (wound->treated) {
armWounds += wound->value / 2;
}
else {
armWounds += wound->value;
}
}
woundList = woundList->next;
}
/**< @todo: Value of all arm wounds is now stored in armWounds, do something with it here. */
/**< Calculate all head wounds, we'll have to go through the wound linkedlist to count all head wounds. */
woundList = target->chr.wounds;
while (woundList) {
wound = (wound_t *)woundList->data;
if ((wound->location == WOUND_HEAD) && wound->affectSkill) {
if (wound->treated) {
headWounds += wound->value / 2;
}
else {
headWounds += wound->value;
}
}
woundList = woundList->next;
}
/**< @todo: Value of all head wounds is now stored in headWounds, do something with it here. */
return returnValue;
}
/**
* @brief Return the increase in turn units used by an actor due to wounds.
* @param[in] target The injured actor we are calculating the increase in turn units for.
*/
int G_ActorShootTUIncreaseByWounds (edict_t *target)
{
linkedList_t *woundList;
wound_t *wound;
int armWounds = 0, returnValue = 0;
/**< Calculate all arm wounds, we'll have to go through the wound linkedlist to count all arm wounds. */
woundList = target->chr.wounds;
while (woundList) {
wound = (wound_t *)woundList->data;
if ((wound->location == WOUND_ARMS) && wound->affectSkill) {
if (wound->treated) {
armWounds += wound->value / 2;
}
else {
armWounds += wound->value;
}
}
woundList = woundList->next;
}
/**< @todo: Value of all arm wounds is now stored in armWounds, do something with it here. */
return returnValue;
}
/**
* @brief Treat the actor to slightly heal, and prevent bleeding of untreated combat wounds.
* @note Type of healing is 1 for wounds, 2 for morale, 3 for stun.
* @param[in] target Who's wounds are being treated.
* @param[in] damage /1000=type of healing, %1000 = amount of healing.
*/
void G_ActorTreat (edict_t *target, const int damage)
{
int type, value, index, amount, woundNumber;
linkedList_t *woundList;
wound_t *treatWound;
/**< Determine the type and value of the healing. */
type = damage / 1000;
value = damage % 1000;
/**< Sanity check on 'type' here. *
* I am leaving it out the value check in case we want to subtract morale or something. */
if (type < 0)
type = -type;
if ( type == HEAL ) {
/**< First we locate the worst wound on the person being treated */
index = 0;
amount = 0;
woundNumber = 0;
woundList = target->chr.wounds;
while (woundList) {
treatWound = (wound_t *)woundList->data;
if ((!treatWound->treated) && (treatWound->value > amount)) {
amount = treatWound->value;
woundNumber = index;
}
index++;
woundList = woundList->next;
}
woundList = target->chr.wounds;
if(woundList) {
treatWound = (wound_t *)LIST_GetByIdx(woundList, woundNumber);
if(treatWound->treated == 0) {
/**< Heal the wound a bit. We will simply subtract 10% of the wound from itself. */
treatWound->value -= treatWound->value / 10;
treatWound->treated = 1;
target->HP += treatWound->value / 10;
}
}
}
else if (type == MORALE) {
target->morale -= value;
target->morale = min (target->morale, 100);
target->morale = max (target->morale, 0);
}
else if (type == STUN) {
target->STUN -= value;
target->STUN = min (target->STUN, 255);
target->STUN = max (target->STUN, 0);
}
else {
}
}
It took only 50 minutes to do. Now you can look it over for things not matching your code standards if that's what you want to do.