/* =============== Cmd_Math_f Compares two cvars, if true vstr the third, if false vstr the forth =============== */ void Cmd_Math_f( void ) { char *v; char *v1; char *v2; char *op; if (Cmd_Argc () == 3) { v = Cmd_Argv( 1 ); op = Cmd_Argv( 2 ); if ( !strcmp( op, "++" ) ) { Cvar_SetValue( v, ( Cvar_VariableIntegerValue( v ) + 1 ) ); } else if ( !strcmp( op, "--" ) ) { Cvar_SetValue( v, ( Cvar_VariableIntegerValue( v ) - 1 ) ); } else { Com_Printf ("math = \nmath \nmath ++\nmath --\nvalid operators are + - * / \n"); return; } } else if (Cmd_Argc () == 4) { v = Cmd_Argv( 1 ); op = Cmd_Argv( 2 ); v1 = Cmd_Argv( 3 ); if ( !strcmp( op, "+" ) ) { Cvar_SetValue( v, ( Cvar_VariableIntegerValue( v ) + Cvar_VariableIntegerValue( v1 ) ) ); } else if ( !strcmp( op, "-" ) ) { Cvar_SetValue( v, ( Cvar_VariableIntegerValue( v ) - Cvar_VariableIntegerValue( v1 ) ) ); } else if ( !strcmp( op, "*" ) ) { Cvar_SetValue( v, ( Cvar_VariableIntegerValue( v ) * Cvar_VariableIntegerValue( v1 ) ) ); } else if ( !strcmp( op, "/" ) ) { if ( ! ( Cvar_VariableIntegerValue( v1 ) == 0 ) ) { Cvar_SetValue( v, ( Cvar_VariableIntegerValue( v ) / Cvar_VariableIntegerValue( v1 ) ) ); } } else { Com_Printf ("math = \nmath \nmath ++\nmath --\nvalid operators are + - * / \n"); return; } } else if (Cmd_Argc () == 6) { v = Cmd_Argv( 1 ); v1 = Cmd_Argv( 3 ); op = Cmd_Argv( 4 ); v2 = Cmd_Argv( 5 ); if ( !strcmp( op, "+" ) ) { Cvar_SetValue( v, ( Cvar_VariableIntegerValue( v1 ) + Cvar_VariableIntegerValue( v2 ) ) ); } else if ( !strcmp( op, "-" ) ) { Cvar_SetValue( v, ( Cvar_VariableIntegerValue( v1 ) - Cvar_VariableIntegerValue( v2 ) ) ); } else if ( !strcmp( op, "*" ) ) { Cvar_SetValue( v, ( Cvar_VariableIntegerValue( v1 ) * Cvar_VariableIntegerValue( v2 ) ) ); } else if ( !strcmp( op, "/" ) ) { if ( ! ( Cvar_VariableIntegerValue( v2 ) == 0 ) ) { Cvar_SetValue( v, ( Cvar_VariableIntegerValue( v1 ) / Cvar_VariableIntegerValue( v2 ) ) ); } } else { Com_Printf ("math = \nmath \nmath ++\nmath --\nvalid operators are + - * / \n"); return; } } else { Com_Printf ("math = \nmath \nmath ++\nmath --\nvalid operators are + - * / \n"); return; } }