|
@@ -15,7 +15,7 @@ function resetPossibleEvents() {
|
|
|
function addPossibleEvent(pEvent) {
|
|
function addPossibleEvent(pEvent) {
|
|
|
possibleEvents.push(
|
|
possibleEvents.push(
|
|
|
{
|
|
{
|
|
|
- pEvent : pEvent,
|
|
|
|
|
|
|
+ event : pEvent,
|
|
|
weight : getEventWeight(pEvent)
|
|
weight : getEventWeight(pEvent)
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
@@ -23,24 +23,25 @@ function addPossibleEvent(pEvent) {
|
|
|
|
|
|
|
|
// à faire
|
|
// à faire
|
|
|
function getEventWeight(pEvent) {
|
|
function getEventWeight(pEvent) {
|
|
|
- let weight = 1;
|
|
|
|
|
- return weight;
|
|
|
|
|
|
|
+ let eventWeight;
|
|
|
|
|
+ for (let i = 0; i < pEvent.treshold.length; i++) {
|
|
|
|
|
+ eventWeight *= 1 - pEvent.coefficient[i] * (1 - ( indicators[i] / pEvent.treshold[i])) ** (1/2) ;
|
|
|
|
|
+ }
|
|
|
|
|
+ return eventWeight;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
function testPossibleEvent(pEvent) {
|
|
function testPossibleEvent(pEvent) {
|
|
|
- if (
|
|
|
|
|
- (clergy.wealth <= pEvent.clergy.wealth) &&
|
|
|
|
|
- (clergy.influence <= pEvent.clergy.influence) &&
|
|
|
|
|
- (nobility.wealth <= pEvent.nobility.wealth) &&
|
|
|
|
|
- (nobility.influence <= pEvent.nobility.influence) &&
|
|
|
|
|
- (nobility.army <= pEvent.nobility.army) &&
|
|
|
|
|
- (people.wealth <= pEvent.people.wealth) &&
|
|
|
|
|
- (people.wellBeing <= pEvent.people.wellBeing)
|
|
|
|
|
- ) {
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ let test = true;
|
|
|
|
|
+ let i = 0;
|
|
|
|
|
+ while ((test) && (i < indicators.length)) {
|
|
|
|
|
+ if (indicators[i] <= pEvent.treshold[i]) {
|
|
|
|
|
+ test = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ i++
|
|
|
}
|
|
}
|
|
|
- return false;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return test;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -55,3 +56,11 @@ function allPossibleEvents() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+function getTotalWeight() {
|
|
|
|
|
+ let totalWeight;
|
|
|
|
|
+ for (let i = 0; i < possibleEvents.length; i++) {
|
|
|
|
|
+ totalWeight += possibleEvents[i].weight;
|
|
|
|
|
+ }
|
|
|
|
|
+ return totalWeight;
|
|
|
|
|
+}
|