Ejemplo n.º 1
0
/*!
	Returns the variant as a double if the variant has type()
	StringType, CString, DoubleType, IntType, UInt, or Bool; or 0.0 otherwise.

	If \a ok is non-null, \a *ok is set to TRUE if the value could be
	converted to a double and FALSE otherwise.

	\sa asDouble()
*/
double cVariant::toDouble( bool* ok ) const
{
	if ( typ == StringType )
		return ( ( QString * ) value.ptr )->toDouble( ok );

	if ( ok )
		*ok = canCast( DoubleType );

	if ( typ == DoubleType )
		return value.d;

	if ( typ == IntType )
		return ( double ) value.i;

	if ( typ == LongType )
		return ( double ) value.d;

	if ( typ == BaseCharType )
	{
		P_CHAR pChar = static_cast<P_CHAR>( value.ptr );
		return pChar ? ( double ) pChar->serial() : ( double ) INVALID_SERIAL;
	}

	if ( typ == ItemType )
	{
		P_ITEM pItem = static_cast<P_ITEM>( value.ptr );
		return pItem ? ( double ) pItem->serial() : ( double ) INVALID_SERIAL;
	}

	return 0.0;
}
Ejemplo n.º 2
0
/*!
	Returns the variant as an int if the variant has type()
	StringType, CString, IntType, UInt, DoubleType, Bool or KeySequence; or 0 otherwise.

	If \a ok is non-null, \a *ok is set to TRUE if the value could be
	converted to an int and FALSE otherwise.

	\sa asInt() canCast()
*/
int cVariant::toInt( bool* ok ) const
{
	if ( typ == StringType )
		return hex2dec( *( ( QString * ) value.ptr ) ).toInt( ok );

	if ( ok )
		*ok = canCast( IntType );

	if ( typ == IntType )
		return value.i;

	if ( typ == LongType )
		return ( int ) value.d;

	if ( typ == DoubleType )
		return ( int ) value.d;

	if ( typ == BaseCharType )
	{
		P_CHAR pChar = static_cast<P_CHAR>( value.ptr );
		return pChar ? pChar->serial() : INVALID_SERIAL;
	}

	if ( typ == ItemType )
	{
		P_ITEM pItem = static_cast<P_ITEM>( value.ptr );
		return pItem ? pItem->serial() : INVALID_SERIAL;
	}

	return 0;
}
Ejemplo n.º 3
0
skillReturnType Heal::Use(Creature &caster) {
    skillReturnType r = canCast(caster);
    if (r == SKILL_SUCCESS) {
        caster.takeCost(getCost());
        caster.heal(baseHealPoints);
    }
    return r;
}
Ejemplo n.º 4
0
void Ability::execute(Pawn* user) {
	if (canCast()) {
		user->stun(M_CAST_TIME);	//Stun the user for the duration of the cast time.
		doExecuteLogic(user);	//Do ability-specific execution logic.
		activate();
		mExecutionSound.setPosition(sf::Vector3f(user->getPosition().x, user->getPosition().y, 0.f));
		mExecutionSound.play();
	}
}
Ejemplo n.º 5
0
skillReturnType Melee::Use(Creature &caster, Creature &target) {
skillReturnType r = canCast(caster);
    if (r == SKILL_SUCCESS) {
        caster.takeCost(getCost());

        Points dmg = {0,0,0};
        dmg.HP = baseDamage + runStatMultipliers(caster.getStats(), statDamageFactors);
        dmg = caster.runDamageMultipliers(dmg, getDamageType());

        target.damage(dmg, getDamageType());
    }
    return r;

}
Ejemplo n.º 6
0
bool cVariant::cast( Type t )
{
	switch ( t )
	{
	case StringType:
		asString();
		break;
	case IntType:
		asInt();
		break;
	case DoubleType:
		asDouble();
		break;
	default:
		( *this ) = cVariant();
	}
	return canCast( t );
}
Ejemplo n.º 7
0
skillReturnType MagicTouch::Use(Creature &caster, Creature &target) {
    skillReturnType r = canCast(caster);

    if (r == SKILL_SUCCESS) {
        caster.takeCost(getCost());
        Points dmg = {0,0,0};
        dmg.HP = baseDamage + runStatMultipliers(caster.getStats(), statDamageFactors);
        dmg = caster.runDamageMultipliers(dmg, getDamageType());
        target.damage(dmg, getDamageType());

        //Clone the "master copy" of the buff
        Buff *newBuff = debuff->Clone();

        //set buff duration based on stats
        newBuff->turnsLeft = debuff->getBaseDuration() + runStatMultipliers(caster.getStats(), debuff->getDurationMultipliers());
        newBuff->apply(target);
    }
    return r;
}
Ejemplo n.º 8
0
/*
* Routine: ValidateParams(int nFunc, expr_t *pArgs)
* Purpose: 
* Algorithm:
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: None
*/
int 
ValidateParams(int nFunc, expr_t *pArgs)
{
	int i = 0,
		nArgs;
	expr_t *pCurrentArg;
	char msg[80];
	
	pCurrentArg = getHead(pArgs->ArgList);
	if (pCurrentArg)
	{
		
		if (pCurrentArg->nFlags & EXPR_FL_REPL)	/* replacement sets can be arbitrarily long */
			return(0);
	}

	nArgs = length(pArgs->ArgList);
	if (nArgs != arFuncInfo[nFunc].nParams)
	{
		
		sprintf(msg, "wanted %d args, found %d", arFuncInfo[nFunc].nParams, nArgs);
		ReportError(QERR_BAD_PARAMS, msg, 0);
		return(1);
	}
	
	for (pCurrentArg = (expr_t *)getHead(pArgs->ArgList); pCurrentArg; pCurrentArg = (expr_t *)getNext(pArgs->ArgList))
	{
		if (!canCast(pCurrentArg->nFlags & EXPR_TYPE_MASK,arFuncArgs[nFunc][i]) && 
			(arFuncArgs[nFunc][i] != EXPR_FL_TYPESHIFT))
		{
			sprintf(msg, "type mismatch in call to %s() on parameter %d (%d/%d)", 
				KeywordText(arFuncInfo[nFunc].nKeyword), 
				i + 1, 
				(pCurrentArg->nFlags & EXPR_TYPE_MASK), arFuncArgs[nFunc][i]);
			ReportErrorNoLine(QERR_BAD_PARAMS, msg, 0);
			return(1);
		}
		i += 1;
	}

	return(0);
}