project-navigation
Personal tools

Author Topic: Undefined Reference  (Read 14133 times)

Offline criusmac

  • Squad Leader
  • ****
  • Posts: 168
    • View Profile
Re: Undefined Reference
« Reply #15 on: September 18, 2009, 12:09:54 am »
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: [Select]
/**
 * @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.

Offline Duke

  • Administrator
  • PHALANX veteran
  • *****
  • Posts: 1037
    • View Profile
Re: Undefined Reference
« Reply #16 on: September 18, 2009, 12:14:02 am »
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 ??
« Last Edit: September 18, 2009, 12:20:41 am by Duke »

Offline Destructavator

  • Combination Multiple Specialty Developer
  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 1908
  • Creater of Scorchcrafter, knows the zarakites...
    • View Profile
Re: Undefined Reference
« Reply #17 on: September 18, 2009, 12:24:54 am »
Quote
Hey guys, does anyone know a way to split an svn checkout into smaller pieces ??

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.

Offline Kildor

  • Project Artist
  • Captain
  • ***
  • Posts: 757
  • Project mapper and some other stuff`er
    • View Profile
    • http://ufoai.nx0.ru
Re: Undefined Reference
« Reply #18 on: September 18, 2009, 04:33:05 am »
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.

Offline Destructavator

  • Combination Multiple Specialty Developer
  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 1908
  • Creater of Scorchcrafter, knows the zarakites...
    • View Profile
Re: Undefined Reference
« Reply #19 on: September 18, 2009, 04:35:31 am »
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.)

Offline criusmac

  • Squad Leader
  • ****
  • Posts: 168
    • View Profile
Re: Undefined Reference
« Reply #20 on: September 18, 2009, 05:51:43 am »
Ok, well, assuming I manage to download all of the source code and needed files, and I move all my code into g_actor.c as told, may I get some advice on how to fix my memory allocation problem?

Right now, as far as I can tell, the problem you are stating Mattn (aside from the comments on how poorly written my code in progress is) is that the dll is not using the same heap manager as the rest of the code. If this is the case, even if I create my own linked list in the dll, it will run into the same problem.

From what I understand, the code should have been written so that only one module is handling all the allocations and the frees. Any allocations in the dll should have already been using the same allocator.. If this is the case, there shouldn't be any problem using the existing linked list code in the dll. If this is not the case, there are going to be a lot of other problems in the dll code if it does any sort of memory allocations at all... Even if I create my own linked list to do so.

So, right now, the way I see it... I can't continue properly, since the suggestion given and the reason given by you are conflicting with each other.

IE: If different memory pools are being used, then I can't create my own linked list to get around it anyways. My code absolutely *must* be able to transfer the memory contents between the dll portion and the rest of the code since wounds need to be handled in combat, and hospitals, and save files, and etc. Is what I'm trying to do impossible due to this?

Offline criusmac

  • Squad Leader
  • ****
  • Posts: 168
    • View Profile
Re: Undefined Reference
« Reply #21 on: September 18, 2009, 06:33:26 am »
Ok, I decided I would try to do a full checkout since no other options were working, and I supplied my existing development directory hoping it wouldn't download the unchanged files. This appears to have not worked at all, and I killed it after 382 megs were downloaded. I figure I can just not use the internet for a week or so, and get it back. Since I now have pretty much all the source code, I'm ready for whatever suggestions you guys have.

I wonder why everything is a red exclamation mark. I'll have to look up what that means.

*edit*
Ok, I changed everything to a green checkmark by reverting the directories. That didn't use any bandwidth, so that's nice. Everything appears to be up to date now... Of what I managed to download. I just won't run the game until I get the rest of the files. It's too bad svn can't tell the files are old versions and update them without saving the revision numbers.. But alas, I guess it's just not done often enough to warrant implementation.
« Last Edit: September 18, 2009, 06:50:29 am by criusmac »

Offline Kildor

  • Project Artist
  • Captain
  • ***
  • Posts: 757
  • Project mapper and some other stuff`er
    • View Profile
    • http://ufoai.nx0.ru
Re: Undefined Reference
« Reply #22 on: September 18, 2009, 06:50:16 am »
> I wonder why everything is a red exclamation mark. I'll have to look up what that means.
Screenshot, please.

PS: And you *must* checkout SVN to empty folder or you will get errors.

Offline criusmac

  • Squad Leader
  • ****
  • Posts: 168
    • View Profile
Re: Undefined Reference
« Reply #23 on: September 18, 2009, 06:52:30 am »
The red exclamation mark just means it thinks I modified the file, and it merged the new changes in.

And no, I don't need to checkout SVN to empty folder, and I won't get errors. I can say this since I just did this. Not a single error, just every file got merged instead of reverted.

Offline criusmac

  • Squad Leader
  • ****
  • Posts: 168
    • View Profile
Re: Undefined Reference
« Reply #24 on: September 18, 2009, 07:28:11 am »
Well, in the end, I had to just update everything. $5 isn't enough to worry about yet. So everything is updated and reverted.

This still leaves me with my original problem. A bunch of linked list undefined references.

Linking dynamic library: ..\..\base\game.dll
.objs\game\src\game\g_actor.o: In function `G_ActorDamage':C:/cprogs/UFOAI-2.3-dev/src/game/g_actor.c:202: undefined reference to `LIST_AddPointer'
.objs\game\src\game\g_actor.o: In function `G_ActorTreat':C:/cprogs/UFOAI-2.3-dev/src/game/g_actor.c:319: undefined reference to `LIST_GetByIdx

From what I can tell, the suggestion was to create my own linked list not using any of the undefined referenced code... Or, in other words, copy and paste all the linked list functions to the dll. If this is still what you want, I can go ahead and do that.
« Last Edit: September 18, 2009, 07:30:04 am by criusmac »

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Undefined Reference
« Reply #25 on: September 18, 2009, 09:10:38 am »
do your own linked list please

Offline Kildor

  • Project Artist
  • Captain
  • ***
  • Posts: 757
  • Project mapper and some other stuff`er
    • View Profile
    • http://ufoai.nx0.ru
Re: Undefined Reference
« Reply #26 on: September 18, 2009, 10:07:24 am »
> And no, I don't need to checkout SVN to empty folder, and I won't get errors. I can say this since I just did this. Not a single error, just every file got merged instead of reverted.
Really? I`ve not known it, thanks for answer.