A_RelayCustomValue is an action that changes the custom value of the actor's target or tracer. If Var1's upper 16 bits are 0, the target is used; if they are 1, the tracer is used. Var1's lower 16 bits and Var2 control how the custom value is modified:
Var2
|
New custom value
|
0
|
Var1's lower 16 bits
|
1
|
Old custom value - Var1's lower 16 bits
|
2
|
Old custom value + Var1's lower 16 bits
|
3
|
Apply modulo of Var1's lower 16 bits to old custom value
|
4
|
Old custom value ÷ Var1's lower 16 bits
|
5
|
Old custom value × Var1's lower 16 bits
|
If Var1's lower 16 bits are 0, the actor's own custom value is used in the above calculations instead. Note that if an attempt is made to divide by zero (i.e.: both Var1's lower 16 bits and the actor's custom value are 0, and Var2 is 4), this action will do nothing.
This action originates from the v2.0 modification SRB2Morphed and was added to SRB2 itself in v2.1.
Code – A_RelayCustomValue
|
|
// Function: A_RelayCustomValue
//
// Description: Manipulates the custom value of the object's target/tracer.
//
// var1:
// lower 16 bits:
// if var1 == 0, use own custom value
// else, use var1 value
// upper 16 bits = 0 - target, 1 - tracer
// var2:
// if var2 == 5, multiply the target's custom value by var1
// else if var2 == 4, divide the target's custom value by var1
// else if var2 == 3, apply modulo var1 to the target's custom value
// else if var2 == 2, add var1 to the target's custom value
// else if var2 == 1, substract var1 from the target's custom value
// else if var2 == 0, replace the target's custom value with var1
//
void A_RelayCustomValue(mobj_t *actor)
{
INT32 locvar1 = var1;
INT32 locvar2 = var2;
INT32 temp; // reference value - var1 lower 16 bits changes this
INT32 tempT; // target's value - changed to tracer if var1 upper 16 bits set, then modified to become final value
#ifdef HAVE_BLUA
if (LUA_CallAction("A_RelayCustomValue", actor))
return;
#endif
if ((!(locvar1 >> 16) && !actor->target) || ((locvar1 >> 16) && !actor->tracer))
return;
// reference custom value
if ((locvar1 & 65535) == 0)
temp = actor->cusval; // your own custom value
else
temp = (locvar1 & 65535); // var1 value
if (!(locvar1 >> 16)) // target's custom value
tempT = actor->target->cusval;
else // tracer's custom value
tempT = actor->tracer->cusval;
if (temp == 0 && locvar2 == 4)
return; // DON'T DIVIDE BY ZERO
// now get new cusval using target's and the reference
if (locvar2 == 5) // multiply
tempT *= temp;
else if (locvar2 == 4) // divide
tempT /= temp;
else if (locvar2 == 3) // modulo
tempT %= temp;
else if (locvar2 == 2) // add
tempT += temp;
else if (locvar2 == 1) // subtract
tempT -= temp;
else // replace
tempT = temp;
// finally, give target/tracer the new cusval!
if (!(locvar1 >> 16)) // target
actor->target->cusval = tempT;
else // tracer
actor->tracer->cusval = tempT;
}
|
|