/* c'est la table qui contient toutes les lois choisi par le joueur */ var tableLaws = []; var tableEventsLaws = []; /* Lister les lois votee */ function genListeTableLaws() { let res = ""; for (var i = 0; i < tableLaws.length; i++) { res = res + genTableLaw(tableLaws[i][0].id, tableLaws[i][1]); } return res; } function genTableLaw(lawID, lawLevel) { return '

' + laws[lawID].nom + '

' + laws[lawID].descriptions[lawLevel] + "

"; } function genTableEventsLaw(eventID, id) { return '

' + events[eventID].lois[id].nom + '

' + events[eventID].lois[id].descriptions[0] + "

"; } /* id d'une loi non evenementiel au hazard */ function randLaw(selectedLaws){ let found = false; let id; while (!found) { if ((tableLaws.length + selectedLaws.length) >= laws.length) { id = -1; break; } id = randInt(0, laws.length - 1); found = true; for (var i = 0; i < selectedLaws.length; i++) { if (selectedLaws[i].id == id) { found = false; } } for (var i = 0; i < tableLaws.length; i++) { if (tableLaws[i][0].id == id) { found = false; } } } return id; } const numberAddLaws = 3; function genListeAddLaws() { console.log("genListeAddLaws"); let selectedLaws = []; let res = ""; for (var i = 0; i < numberAddLaws; i++) { let newLaw = randLaw(selectedLaws); selectedLaws.push(laws[newLaw]); if (newLaw > -1) { res = res + genAddLaw(newLaw); } } return res; } function genAddLaw(id){ return "

" + laws[id].nom + '

' + laws[id].descriptions[0] + "

"; } function addLaw(id){ tableLaws.unshift([laws[id], 0]); updateIndicatorsAddLaws(laws[id]); turnForward(); } /* Ajouter une loi evenementiel */ function genAddEventLaw(eventID, id){ return "

" + events[eventID].lois[id].nom + '

' + events[eventID].lois[id].descriptions[0] + "

"; } function addEventLaw(eventID, id){ tableEventsLaws.unshift([eventID, id]); updateIndicatorsAddLaws(events[eventID].lois[id]); turnForward(); } /* Supprimer une loi */ function genListeRemoveLaws() { let res = ""; for (var i = 0; i < tableLaws.length; i++) { res = res + genRemoveLaw(tableLaws[i][0].id, tableLaws[i][1], i); } return res; } function genRemoveLaw(lawID, lawLevel, num) { return '

' + laws[lawID].nom + '

' + laws[lawID].descriptions[lawLevel] + "

"; } function removeLaw(pos, lawID){ tableLaws.splice(pos, 1); updateIndicatorsRemoveLaws(laws[lawID]); turnForward() } /* Ameliorer une loi */ function genListeUpgradeLaws() { let res = ""; let num = 0; for (var i = 0; i < tableLaws.length; i++) { if (tableLaws[i][1] < 2) { res = res + genUpgradeLaw(tableLaws[i][0].id, tableLaws[i][1], num); num++; } } return res; } function genUpgradeLaw(lawID, lawLevel, num) { return "

" + laws[lawID].nom + '

' + laws[lawID].descriptions[lawLevel] + "

"; } function upgradeLaw(pos, lawID){ tableLaws[pos][1] = tableLaws[pos][1] + 1; updateIndicatorsUpgradeLaws(laws[lawID]); turnForward() }