A_SetCustomValue is an action that changes the actor's custom value. Var1 and Var2 control how the custom value is modified:
Var2
|
New custom value
|
0
|
Var1
|
1
|
Old custom value - Var1
|
2
|
Old custom value + Var1
|
3
|
Apply modulo Var1 to old custom value
|
4
|
Old custom value ÷ Var1
|
5
|
Old custom value × Var1
|
Note that if an attempt is made to divide by zero (i.e.: Var1 is 0, and Var2 is 4), this action will do nothing. If development mode is enabled when this action is called, messages will be printed into the console stating the initial and new custom values.
This action originates from the v2.0 modification SRB2Morphed and was added to SRB2 itself in v2.1.
Code – A_SetCustomValue
|
|
// Function: A_SetCustomValue
//
// Description: Changes the custom value of an object.
//
// var1 = manipulating value
// var2:
// if var2 == 5, multiply the custom value by var1
// else if var2 == 4, divide the custom value by var1
// else if var2 == 3, apply modulo var1 to the custom value
// else if var2 == 2, add var1 to the custom value
// else if var2 == 1, substract var1 from the custom value
// else if var2 == 0, replace the custom value with var1
//
void A_SetCustomValue(mobj_t *actor)
{
INT32 locvar1 = var1;
INT32 locvar2 = var2;
#ifdef HAVE_BLUA
if (LUA_CallAction("A_SetCustomValue", actor))
return;
#endif
if (cv_debug)
CONS_Printf("Init custom value is %d\n", actor->cusval);
if (locvar1 == 0 && locvar2 == 4)
return; // DON'T DIVIDE BY ZERO
// no need for a "temp" value here, just modify the cusval directly
if (locvar2 == 5) // multiply
actor->cusval *= locvar1;
else if (locvar2 == 4) // divide
actor->cusval /= locvar1;
else if (locvar2 == 3) // modulo
actor->cusval %= locvar1;
else if (locvar2 == 2) // add
actor->cusval += locvar1;
else if (locvar2 == 1) // subtract
actor->cusval -= locvar1;
else // replace
actor->cusval = locvar1;
if(cv_debug)
CONS_Printf("New custom value is %d\n", actor->cusval);
}
|
|