Ejemplo n.º 1
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
float FuzzyWeight_r(int *inventory, fuzzyseperator_t *fs)
{
	float scale, w1, w2;

	if (inventory[fs->index] < fs->value)
	{
		if (fs->child) return FuzzyWeight_r(inventory, fs->child);
		else return fs->weight;
	} //end if
	else if (fs->next)
	{
		if (inventory[fs->index] < fs->next->value)
		{
			//first weight
			if (fs->child) w1 = FuzzyWeight_r(inventory, fs->child);
			else w1 = fs->weight;
			//second weight
			if (fs->next->child) w2 = FuzzyWeight_r(inventory, fs->next->child);
			else w2 = fs->next->weight;
			//the scale factor
			scale = (inventory[fs->index] - fs->value) / (fs->next->value - fs->value);
			//scale between the two weights
			return scale * w1 + (1 - scale) * w2;
		} //end if
		return FuzzyWeight_r(inventory, fs->next);
	} //end else if
	return fs->weight;
} //end of the function FuzzyWeight_r
Ejemplo n.º 2
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
float FuzzyWeight_r( int *inventory, fuzzyseperator_t *fs ) {
	float scale, w1, w2;

	if ( inventory[fs->index] < fs->value ) {
		if ( fs->child ) {
			return FuzzyWeight_r( inventory, fs->child );
		} else { return fs->weight;}
	} //end if
	else if ( fs->next ) {
		if ( inventory[fs->index] < fs->next->value ) {
			//first weight
			if ( fs->child ) {
				w1 = FuzzyWeight_r( inventory, fs->child );
			} else { w1 = fs->weight;}
			//second weight
			if ( fs->next->child ) {
				w2 = FuzzyWeight_r( inventory, fs->next->child );
			} else { w2 = fs->next->weight;}
			//the scale factor
			if(fs->next->value == MAX_INVENTORYVALUE) // is fs->next the default case?
	       		return w2;      // can't interpolate, return default weight
			else
				scale = (float) (inventory[fs->index] - fs->value) / (fs->next->value - fs->value);
			//scale between the two weights
			return (1 - scale) * w1 + scale * w2;
		} //end if
		return FuzzyWeight_r( inventory, fs->next );
	} //end else if
	return fs->weight;
} //end of the function FuzzyWeight_r
Ejemplo n.º 3
0
float FuzzyWeight_r(int *inventory, fuzzyseperator_t *fs) {
    float scale, w1, w2;

    if (inventory[fs->index] < fs->value) {
        if (fs->child) {
            //Com_Printf("FuzzyWeight_r fs->child = %f type = %i\n", FuzzyWeight_r(inventory, fs->child), fs->type);
            return FuzzyWeight_r(inventory, fs->child);
        } else {
            //Com_Printf("FuzzyWeight_r fs->weight = %f type = %i\n", fs->weight, fs->type);
            return fs->weight;
        }
    } else if (fs->next) {
        if (inventory[fs->index] < fs->next->value) {
            //first weight
            if (fs->child) w1 = FuzzyWeight_r(inventory, fs->child);
            else w1 = fs->weight;
            //second weight
            if (fs->next->child) w2 = FuzzyWeight_r(inventory, fs->next->child);
            else w2 = fs->next->weight;
            //the scale factor
            if (fs->next->value == MAX_INVENTORYVALUE) // is fs->next the default case?
                return w2; // can't interpolate, return default weight
            else
                scale = (float) (inventory[fs->index] - fs->value) / (fs->next->value - fs->value);
            //scale between the two weights
            return (1 - scale) * w1 + scale * w2;
        } //end if
        //Com_Printf("fuzzyweight_r = %f\n", FuzzyWeight_r(inventory, fs->next));
        return FuzzyWeight_r(inventory, fs->next);
    } //end else if
    //Com_Printf("fuzzyweight = %f\n", fs->weight);
    return fs->weight;
} //end of the function FuzzyWeight_r
Ejemplo n.º 4
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
float FuzzyWeight( int *inventory, weightconfig_t *wc, int weightnum ) {
#ifdef EVALUATERECURSIVELY
	return FuzzyWeight_r( inventory, wc->weights[weightnum].firstseperator );
#else
	fuzzyseperator_t *s;

	s = wc->weights[weightnum].firstseperator;
	if ( !s ) {
		return 0;
	}
	while ( 1 )
	{
		if ( inventory[s->index] < s->value ) {
			if ( s->child ) {
				s = s->child;
			} else { return s->weight;}
		} //end if
		else
		{
			if ( s->next ) {
				s = s->next;
			} else { return s->weight;}
		} //end else
	} //end if
	return 0;
#endif
} //end of the function FuzzyWeight