Exemple #1
0
void FParser::OPminus(svalue_t &result, int start, int n, int stop)
{
	svalue_t left, right;
	
	// do they mean minus as in '-1' rather than '2-1'?
	if(start == n)
	{
		// kinda hack, hehe
		EvaluateExpression(right, n+1, stop);
	}
	else
	{
		evaluate_leftnright(start, n, stop);
	}
	
	// haleyjd: 8-17
	if(left.type == svt_fixed || right.type == svt_fixed)
	{
		result.type = svt_fixed;
		result.value.f = fixedvalue(left) - fixedvalue(right);
	}
	else
	{
		result.type = svt_int;
		result.value.i = intvalue(left) - intvalue(right);
	}
}
Exemple #2
0
void FParser::OPplus(svalue_t &result, int start, int n, int stop)
{
	svalue_t left, right;
	
	evaluate_leftnright(start, n, stop);
	
  	if (left.type == svt_string)
    {
      	if (right.type == svt_string)
		{
			result.string.Format("%s%s", left.string.GetChars(), right.string.GetChars());
		}
      	else if (right.type == svt_fixed)
		{
			result.string.Format("%s%4.4f", left.string.GetChars(), floatvalue(right));
		}
      	else
		{
	  		result.string.Format("%s%i", left.string.GetChars(), intvalue(right));
		}
      	result.type = svt_string;
    }
	// haleyjd: 8-17
	else if(left.type == svt_fixed || right.type == svt_fixed)
	{
		result.type = svt_fixed;
		result.value.f = fixedvalue(left) + fixedvalue(right);
	}
	else
	{
		result.type = svt_int;
		result.value.i = intvalue(left) + intvalue(right);
	}
}
Exemple #3
0
void FParser::OPcmp(svalue_t &result, int start, int n, int stop)
{
	svalue_t left, right;
	
	evaluate_leftnright(start, n, stop);
	
	result.type = svt_int;        // always an int returned
	
	if(left.type == svt_string && right.type == svt_string)
	{
		result.value.i = !strcmp(left.string, right.string);
		return;
	}
	
	// haleyjd: direct mobj comparison when both are mobj
	if(left.type == svt_mobj && right.type == svt_mobj)
	{
		// we can safely assume reference equivalency for
		// AActor's in all cases since they are static for the
		// duration of a level
		result.value.i = (left.value.mobj == right.value.mobj);
		return;
	}
	
	if(left.type == svt_fixed || right.type == svt_fixed)
	{
		result.value.i = (fixedvalue(left) == fixedvalue(right));
		return;
	}
	
	result.value.i = (intvalue(left) == intvalue(right));
}
Exemple #4
0
void setvariablevalue(svariable_t *v, svalue_t newvalue)
{
  if(killscript) return;  // protect the variables when killing script
  
  if(!v) return;
  
  if(v->type == svt_const)
    {
      // const adapts to the value it is set to
      v->type = newvalue.type;

      // alloc memory for string
      if(v->type == svt_string)   // static incase a global_script var
	v->value.s = Z_Malloc(128, PU_STATIC, 0);
    }
  
  if(v->type == svt_int)
    v->value.i = intvalue(newvalue);

  if(v->type == svt_string)
    strcpy(v->value.s, stringvalue(newvalue));

  if(v->type == svt_fixed)
    v->value.fixed = fixedvalue(newvalue);

  if(v->type == svt_mobj)
    v->value.mobj = MobjForSvalue(newvalue);


  if(v->type == svt_pInt)
    *v->value.pI = intvalue(newvalue);

  if(v->type == svt_pString)
    {
      // free old value
      free(*v->value.pS);

      // dup new string
      
      *v->value.pS = strdup(stringvalue(newvalue));
    }

  if(v->type == svt_pFixed)
    *v->value.pFixed = fixedvalue(newvalue);
  
  if(v->type == svt_pMobj)
    *v->value.pMobj = MobjForSvalue(newvalue);
  
  if(v->type == svt_function)
    script_error("attempt to set function to a value\n");

}
Exemple #5
0
void FParser::OPgreaterthanorequal(svalue_t &result, int start, int n, int stop)
{
	svalue_t left, right;
	
	evaluate_leftnright(start, n, stop);
	
	result.type = svt_int;
	
	if(left.type == svt_fixed || right.type == svt_fixed)
		result.value.i = (fixedvalue(left) >= fixedvalue(right));
	else
		result.value.i = (intvalue(left) >= intvalue(right));
}
Exemple #6
0
void FParser::OPgreaterthan(svalue_t &result, int start, int n, int stop)
{
	svalue_t left, right;
	
	evaluate_leftnright(start, n, stop);
	
	// haleyjd: 8-17
	result.type = svt_int;
	if(left.type == svt_fixed || right.type == svt_fixed)
		result.value.i = (fixedvalue(left) > fixedvalue(right));
	else
		result.value.i = (intvalue(left) > intvalue(right));
}
Exemple #7
0
// set a variable to a value from an svalue_t
void svariable_t::setvalue(svalue_t newvalue)
{
  if (killscript) return;  // protect the variables when killing script
  
  if (type == svt_const)
    {
      // const adapts to the value it is set to
      type = newvalue.type;

      // alloc memory for string
      if(type == svt_string)   // static incase a global_script var
	value.s = (char *)Z_Malloc(256, PU_STATIC, 0);
    }

  switch (type)
    {
    case svt_int:
      value.i = intvalue(newvalue);
      break;
    case svt_string:
      strcpy(value.s, stringvalue(newvalue));
      break;
    case svt_fixed:
      value.i = fixedvalue(newvalue).value();
      break;
    case svt_actor:
      value.mobj = MobjForSvalue(newvalue);
      break;
    case svt_pInt:
      *value.pI = intvalue(newvalue);
      break;
    case svt_pString:
      // free old value
      free(*value.pS);
      // dup new string
      *value.pS = strdup(stringvalue(newvalue));
      break;
    case svt_pFixed:
      *value.pFixed = fixedvalue(newvalue);
      break;
    case svt_pActor:
      *value.pMobj = MobjForSvalue(newvalue);
      break;
    case svt_function:
      script_error("attempt to set function to a value\n");
    }
}
Exemple #8
0
void DFsVariable::SetValue(FLevelLocals *Level, const svalue_t &newvalue)
{
	if(type == svt_const)
    {
		// const adapts to the value it is set to
		type = newvalue.type;
    }

	switch (type)
	{
	case svt_int:
		value.i = intvalue(newvalue);
		break;

	case svt_string:
		if (newvalue.type == svt_string)
		{
			string = newvalue.string;
		}
		else
		{
			string = stringvalue(newvalue);
		}
		break;

	case svt_fixed:
		value.fixed = fixedvalue(newvalue);
		break;
	
	case svt_mobj:
		actor = actorvalue(Level, newvalue);
		break;
	
	case svt_pInt:
		*value.pI = intvalue(newvalue);
		break;
	
	case svt_pMobj:
		*value.pMobj = actorvalue(Level, newvalue);
		break;
	
	case svt_function:
		script_error("attempt to set function to a value\n");
		break;

	default:
		script_error("invalid variable type\n");
		break;
	}
}