Development > Newbie Coding

Undefined Reference

<< < (2/6) > >>

criusmac:
There are no patches available for what I'm working on.

I am working on medikits.

criusmac:
After moving all my functions to g_combat.c, I now get different undefined references:


-------------- Build: windows_debug in game ---------------

Compiling: ..\..\src\game\g_combat.c
Linking dynamic library: ..\..\base\game.dll
.objs\game\src\game\g_combat.o: In function `CL_ActorDamage':C:/cprogs/UFOAI-2.3-dev/src/game/g_combat.c:205: undefined reference to `LIST_AddPointer'
.objs\game\src\game\g_combat.o: In function `CL_ActorTreat':C:/cprogs/UFOAI-2.3-dev/src/game/g_combat.c:305: undefined reference to `LIST_GetByIdx'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 2 seconds)
0 errors, 0 warnings
 
So, I've run into the problem that prevents me from adding this code to either cl_actor.c and g_combat.c.

I doubt it'll help any, but here is all the code I'm trying to compile... It is untested, and probably very buggy though, but here it is anyways:


--- Code: ---/**
 * @brief Damage the actor.
 * @param[in] target Who is injured
 * @param[in] damage How much damage is being inflicted
 */
void CL_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;
else /**< This should *never* happen, put out an error or something */
newWound->location %= WOUND_LEGS; /**< WOUND_LEGS is probably the highest enum value, so % by it. */

/**< 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;
}

int CL_ActorAccuracyDecreaseByWounds (edict_t *target)
{
linkedList_t *woundList;
wound_t *wound;
int armWounds = 0, headWounds = 0, returnValue = 0;

/**< Calculate 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 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;
}

int CL_ActorShootTUIncreaseByWounds (edict_t *target)
{
linkedList_t *woundList;
wound_t *wound;
int armWounds = 0, returnValue = 0;

/**< Calculate 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.
 * @param[in] target Who is treated
 * @param[in] damage /1000=type of healing, %1000 = amount of healing.
 */
void CL_ActorTreat (edict_t *target, const int damage)
{
int type, value, index, amount, woundNumber;
linkedList_t *woundList;
wound_t *treatWound;

type = damage / 1000;
value = damage % 1000;

/**< Sanity check on 'value' here if wanted. *
* I am leaving it out 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;
treatWound = (wound_t *)LIST_GetByIdx(woundList, woundNumber);
/**< 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 ---

Mattn:
you can't use the linked list directly. it is using memory pools that are not available in the game lib - keep in mind that the stuff below src/game/ will end in a dll - you can use most of the stuff from src/shared - but very little other stuff.

also please move your code into g_actor.c and change the prefix from CL_Actor* to G_Actor*

be a little bit more verbose on your comments please - describe exactly what each function is supposed to do.

the game lib is using callbacks for e.g. cvars and commands to access the server context (where the game lib is running at) see sv_game.c SV_InitGameProgs

but adding more function callbacks there is only accepted if no other choice is left. so maybe just make wound_t a linked list like this:


--- Code: ---typedef struct wound_s {
[......]
[......]
struct wound_s *next;
} wound_t;
--- End code ---

last but not least - please beware our coding guidelines ;)

criusmac:

--- Quote from: Mattn on September 17, 2009, 09:20:58 pm ---also please move your code into g_actor.c and change the prefix from CL_Actor* to G_Actor*

--- End quote ---

Yes, as stated before, once I figure out where the code is going, I will change the function names.


--- Quote ---be a little bit more verbose on your comments please - describe exactly what each function is supposed to do.

--- End quote ---

Yes, as stated before, this code is *NOT* done, and will not be commented properly until it does exactly what I want. The number of times I've had to change this code already has made many comments vanish.


--- Quote ---the game lib is using callbacks for e.g. cvars and commands to access the server context (where the game lib is running at) see sv_game.c SV_InitGameProgs

but adding more function callbacks there is only accepted if no other choice is left. so maybe just make wound_t a linked list like this:


--- Code: ---typedef struct wound_s {
[......]
[......]
struct wound_s *next;
} wound_t;
--- End code ---

--- End quote ---

So, you are suggesting that I create linkedList_t by copying all the functionality to the dll? I'm not sure exactly what you are suggesting.


--- Quote ---last but not least - please beware our coding guidelines ;)

--- End quote ---

As stated before, I will finalize the code once I have written it. I will not beautify my code until it is complete since it takes so much time to do so, and it keeps changing due to various problems, such as this. This is actually what I figured might be said, which is why I originally didn't want to supply any code.

criusmac:
I am probably over reacting, but it is how I feel, so I will leave it as was... (This attitude of mine always seems to get me into trouble)

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?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version