mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
province capture logic fix - don't create provinces on neutral lands
This commit is contained in:
parent
762ec2c841
commit
4c95d44faa
1 changed files with 10 additions and 14 deletions
|
|
@ -878,8 +878,10 @@ function editStates() {
|
||||||
const {cells, provinces, states, burgs} = pack;
|
const {cells, provinces, states, burgs} = pack;
|
||||||
|
|
||||||
affectedProvinces.forEach(provinceId => {
|
affectedProvinces.forEach(provinceId => {
|
||||||
|
if (!provinces[provinceId]) return; // lands without province captured => do nothing
|
||||||
|
|
||||||
// find states owning at least 1 province cell
|
// find states owning at least 1 province cell
|
||||||
const provCells = cells.i.filter(i => cells.state[i] && cells.province[i] === provinceId);
|
const provCells = cells.i.filter(i => cells.province[i] === provinceId);
|
||||||
const provStates = [...new Set(provCells.map(i => cells.state[i]))];
|
const provStates = [...new Set(provCells.map(i => cells.state[i]))];
|
||||||
|
|
||||||
// province is captured completely => change owner or remove
|
// province is captured completely => change owner or remove
|
||||||
|
|
@ -921,7 +923,7 @@ function editStates() {
|
||||||
// province center is owned by the same state => do nothing for this state
|
// province center is owned by the same state => do nothing for this state
|
||||||
if (stateId === prevOwner.i) return;
|
if (stateId === prevOwner.i) return;
|
||||||
|
|
||||||
// province center is captured by neutrals => remove state
|
// province center is captured by neutrals => remove province
|
||||||
if (!stateId) {
|
if (!stateId) {
|
||||||
provinces[provinceId] = {i: provinceId, removed: true};
|
provinces[provinceId] = {i: provinceId, removed: true};
|
||||||
stateProvinceCells.forEach(i => {
|
stateProvinceCells.forEach(i => {
|
||||||
|
|
@ -938,7 +940,7 @@ function editStates() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// province cells captured by neutrals => clear province
|
// province cells captured by neutrals => remove captured cells from province
|
||||||
if (!stateId) {
|
if (!stateId) {
|
||||||
stateProvinceCells.forEach(i => {
|
stateProvinceCells.forEach(i => {
|
||||||
cells.province[i] = 0;
|
cells.province[i] = 0;
|
||||||
|
|
@ -1036,20 +1038,14 @@ function editStates() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addState() {
|
function addState() {
|
||||||
const states = pack.states,
|
const {cells, states, burgs} = pack;
|
||||||
burgs = pack.burgs,
|
|
||||||
cells = pack.cells;
|
|
||||||
const point = d3.mouse(this);
|
const point = d3.mouse(this);
|
||||||
const center = findCell(point[0], point[1]);
|
const center = findCell(point[0], point[1]);
|
||||||
if (cells.h[center] < 20) {
|
if (cells.h[center] < 20) return tip("You cannot place state into the water. Please click on a land cell", false, "error");
|
||||||
tip("You cannot place state into the water. Please click on a land cell", false, "error");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let burg = cells.burg[center];
|
let burg = cells.burg[center];
|
||||||
if (burg && burgs[burg].capital) {
|
if (burg && burgs[burg].capital) return tip("Existing capital cannot be selected as a new state capital! Select other cell", false, "error");
|
||||||
tip("Existing capital cannot be selected as a new state capital! Select other cell", false, "error");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!burg) burg = addBurg(point); // add new burg
|
if (!burg) burg = addBurg(point); // add new burg
|
||||||
|
|
||||||
const oldState = cells.state[center];
|
const oldState = cells.state[center];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue