Development > Newbie Coding
Undefined Reference
criusmac:
Quicker than I expected since I only worked on the code I am displaying, but here is the same code beautified for your perusal:
--- Code: ---/**
* @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 {
}
}
--- End code ---
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.
Duke:
You're right, g_actor.c was created on Aug 30th by 'splitting code'. I currently can't think of an easy way to provide a small patch for you, sorry.
Are your bandwidth limitations a matter of speed or volume ?
I think your best bet is to hop on the svn train. That would at least save you from working on outdated source. But then again, the first checkout is also some 500 MB and IIRC it has to be done in one session :(
Hey guys, does anyone know a way to split an svn checkout into smaller pieces ??
Destructavator:
--- Quote ---Hey guys, does anyone know a way to split an svn checkout into smaller pieces ??
--- End quote ---
Yes. Some SVN clients, after being interrupted or bombing out with an error, will pick up again where they left off with a standard update command.
The more recent versions of Tortoise SVN do this, I know this is true because sometimes my DSL connection gets interrupted, and the regular "update" with a right-click will work this way, it won't re-download the files it already got as long as they are up-to-date. I've also seen this happen when Tortoise SVN encounters an error.
Kildor:
As workaround you can checkout only src, base\ufos, build, and may be contrib dirs.
Other you can get from your snapshot, to edit code that dirs aren`t needed.
Destructavator:
If you only want certain parts of UFO: AI so you don't have to download the whole thing, you also can use the online SVN browser on Sourceforge - just find the folders with what you want and then click on "download tarball" or something, and you'll get a compressed file with only the folders and files you wanted. I think it is in .tar format or something, I know 7-zip can open it easily. (7-zip itself is tiny.)
Only problem with that method is you can't have it update just the changed files automatically like with Tortoise SVN. (Actually, I think Kildor's suggestion is better.)
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version