I'm pretty sure the problem lies somewhere in the addresses and variable types. The method I am trying to use is to find the address of unit->orderTarget (the caster's target) and match it with puppet's address. I assume that these addresses would be the same. However, I am not certain. That is the theoretical basis of my current solution.
I am fully aware that I can just flag the target unit with a specific timer number by salvaging another value. However, if I wanted to use that solution, I would not have asked for help to either fix my current method's code or look for an entirely different solution.
Code
UNIT* unit;
UNIT* puppet;
for(int i = 0; i < 1700; i++)
{
unit = &unitTable[i];
if(unit->unitId == 79
&& unit->orderSignal == 4
&& unit->orderTarget != NULL
)
{
unit->orderSignal = 0;
// find the target unit
//UNIT* puppet;
for(int i2 = 0; i2 < 1700; i2++)
{
puppet = &unitTable[i2];
if(unit->orderTarget == puppet) // target unit found
{
tE[i2].others[1] = 1; // set its explode-on-death flag
puppet->healthPoints += 100 * 256;
puppet->mainOrderId = 0;
}
}
triggerCD(unit->playerId, 3, 10 * 24);
}
}
UNIT* puppet;
for(int i = 0; i < 1700; i++)
{
unit = &unitTable[i];
if(unit->unitId == 79
&& unit->orderSignal == 4
&& unit->orderTarget != NULL
)
{
unit->orderSignal = 0;
// find the target unit
//UNIT* puppet;
for(int i2 = 0; i2 < 1700; i2++)
{
puppet = &unitTable[i2];
if(unit->orderTarget == puppet) // target unit found
{
tE[i2].others[1] = 1; // set its explode-on-death flag
puppet->healthPoints += 100 * 256;
puppet->mainOrderId = 0;
}
}
triggerCD(unit->playerId, 3, 10 * 24);
}
}
EDIT:
Ugh, I could have just compared puppet's coordinates and match it with orderTarget's coordinates. Problem with this is, what if two units have the same coordinates? Sure, I can check their owners and unit IDs, but what if these are the same too?
However, if any fix can be applied to the code above, it would still be nice to know what went wrong. (Or if there is another completely different approach, that would be welcome too.)
Any suggestions must be able to find the index of the target unit in the unitTable. This, specifically, is what I am looking for, so that I can take the index and apply it to my own struct array.
A fix for the above code is still the most preferred.
Post has been edited 1 time(s), last time on Aug 9 2012, 11:00 am by Sand Wraith.