mirror of
https://github.com/UberGames/ioef.git
synced 2024-11-30 16:01:46 +00:00
Fix weight interpolation thanks to cyrri
This commit is contained in:
parent
8b1b3464d7
commit
78e6b4a904
1 changed files with 10 additions and 4 deletions
|
@ -593,9 +593,12 @@ float FuzzyWeight_r(int *inventory, fuzzyseperator_t *fs)
|
||||||
if (fs->next->child) w2 = FuzzyWeight_r(inventory, fs->next->child);
|
if (fs->next->child) w2 = FuzzyWeight_r(inventory, fs->next->child);
|
||||||
else w2 = fs->next->weight;
|
else w2 = fs->next->weight;
|
||||||
//the scale factor
|
//the scale factor
|
||||||
scale = (float) (inventory[fs->index] - fs->value) / (fs->next->value - fs->value);
|
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
|
//scale between the two weights
|
||||||
return scale * w1 + (1 - scale) * w2;
|
return (1 - scale) * w1 + scale * w2;
|
||||||
} //end if
|
} //end if
|
||||||
return FuzzyWeight_r(inventory, fs->next);
|
return FuzzyWeight_r(inventory, fs->next);
|
||||||
} //end else if
|
} //end else if
|
||||||
|
@ -627,9 +630,12 @@ float FuzzyWeightUndecided_r(int *inventory, fuzzyseperator_t *fs)
|
||||||
if (fs->next->child) w2 = FuzzyWeight_r(inventory, fs->next->child);
|
if (fs->next->child) w2 = FuzzyWeight_r(inventory, fs->next->child);
|
||||||
else w2 = fs->next->minweight + random() * (fs->next->maxweight - fs->next->minweight);
|
else w2 = fs->next->minweight + random() * (fs->next->maxweight - fs->next->minweight);
|
||||||
//the scale factor
|
//the scale factor
|
||||||
scale = (float) (inventory[fs->index] - fs->value) / (fs->next->value - fs->value);
|
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
|
//scale between the two weights
|
||||||
return scale * w1 + (1 - scale) * w2;
|
return (1 - scale) * w1 + scale * w2;
|
||||||
} //end if
|
} //end if
|
||||||
return FuzzyWeightUndecided_r(inventory, fs->next);
|
return FuzzyWeightUndecided_r(inventory, fs->next);
|
||||||
} //end else if
|
} //end else if
|
||||||
|
|
Loading…
Reference in a new issue