aboutsummaryrefslogtreecommitdiffstats
path: root/code
diff options
context:
space:
mode:
authorthilo <thilo@edf5b092-35ff-0310-97b2-ce42778d08ea>2006-10-25 21:20:55 +0000
committerthilo <thilo@edf5b092-35ff-0310-97b2-ce42778d08ea>2006-10-25 21:20:55 +0000
commitee4c1dfc89c79b38c14c71fb7bfd7a3989539ed1 (patch)
treee3617217d5714b3e0bfb328cbe898715e321c0d2 /code
parent47059d15c524ae95f272535c8fb53687ae48e945 (diff)
downloadioquake3-aero-ee4c1dfc89c79b38c14c71fb7bfd7a3989539ed1.tar.gz
ioquake3-aero-ee4c1dfc89c79b38c14c71fb7bfd7a3989539ed1.zip
Fix weight interpolation thanks to cyrri
git-svn-id: svn://svn.icculus.org/quake3/trunk@952 edf5b092-35ff-0310-97b2-ce42778d08ea
Diffstat (limited to 'code')
-rw-r--r--code/botlib/be_ai_weight.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/code/botlib/be_ai_weight.c b/code/botlib/be_ai_weight.c
index b5329db..8d48ee6 100644
--- a/code/botlib/be_ai_weight.c
+++ b/code/botlib/be_ai_weight.c
@@ -593,9 +593,12 @@ float FuzzyWeight_r(int *inventory, fuzzyseperator_t *fs)
if (fs->next->child) w2 = FuzzyWeight_r(inventory, fs->next->child);
else w2 = fs->next->weight;
//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
- return scale * w1 + (1 - scale) * w2;
+ return (1 - scale) * w1 + scale * w2;
} //end if
return FuzzyWeight_r(inventory, fs->next);
} //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);
else w2 = fs->next->minweight + random() * (fs->next->maxweight - fs->next->minweight);
//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
- return scale * w1 + (1 - scale) * w2;
+ return (1 - scale) * w1 + scale * w2;
} //end if
return FuzzyWeightUndecided_r(inventory, fs->next);
} //end else if