From be4caf0c246e00fd9023e60485e62c6b4d382c2b Mon Sep 17 00:00:00 2001 From: Azgaar Date: Thu, 19 Sep 2019 22:20:16 +0300 Subject: [PATCH] 1.0.43 --- main.js | 76 +++++++++++++++++++++++++++++++--- modules/religions-generator.js | 2 +- modules/save-and-load.js | 2 +- modules/ui/heightmap-editor.js | 2 +- modules/ui/tools.js | 1 + 5 files changed, 74 insertions(+), 9 deletions(-) diff --git a/main.js b/main.js index e24b7355..4271b63c 100644 --- a/main.js +++ b/main.js @@ -1175,11 +1175,13 @@ function rankCells() { console.timeEnd('rankCells'); } -// add a zone as an example: rebels along one border +// add a some zones function addZones() { console.time("addZones"); - const data = [], cells = pack.cells, states = pack.states; + const data = [], cells = pack.cells, states = pack.states, burgs = pack.burgs; + //const used = new Uint8Array(cells.i.length); // to store used cells + // rebels along a state border void function addRebels() { const state = states.find(s => s.i && s.neighbors.size > 0 && s.neighbors.values().next().value); if (!state) return; @@ -1191,16 +1193,78 @@ function addZones() { "Mutineers":1, "Rioters":1, "Dissenters":1, "Secessionists":1, "Insurrection":2, "Rebellion":1, "Conspiracy":2}); const name = getAdjective(states[neib].name) + " " + rebels; - data.push({name, cells:cellsArray, fill:"url(#hatch3)"}); + data.push({name, type:"Rebels", cells:cellsArray, fill:"url(#hatch3)"}); }() - // void function addDisease() { + // disease starting in a random city + void function addDisease() { + const burg = ra(burgs.filter(b => b.i && !b.removed)); // random burg + if (!burg) return; - // }() + const cellsArray = [], cost = [], power = rand(20, 40); + const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p}); + queue.queue({e:burg.cell, p:0}); + + while (queue.length) { + const next = queue.dequeue(); + if (cells.burg[next.e] || cells.pop[next.e]) cellsArray.push(next.e); + + cells.c[next.e].forEach(function(e) { + const r = cells.road[next.e]; + const c = r ? Math.max(10 - r, 1) : 100; + const p = next.p + c; + if (p > power) return; + + if (!cost[e] || p < cost[e]) { + cost[e] = p; + queue.queue({e, p}); + } + }); + } + + const adjective = () => ra(["Great", "Silent", "Severe", "Blind", "Unknown", "Loud", "Deadly", "Burning", "Bloody", "Brutal", "Fatal"]); + const animal = () => ra(["Ape", "Bear", "Boar", "Cat", "Cow", "Dog", "Pig", "Fox", "Bird", "Horse", "Rat", "Raven", "Sheep", "Spider", "Wolf"]); + const color = () => ra(["Golden", "White", "Black", "Red", "Pink", "Purple", "Blue", "Green", "Yellow", "Amber", "Orange", "Brown", "Grey"]); + + const type = rw({"Fever":5, "Pestilence":2, "Flu":2, "Pox":2, "Smallpox":2, "Plague":4, "Cholera":2, "Ague":1, "Dropsy":1, "Leprosy":2}); + const name = rw({[color()]:4, [animal()]:2, [adjective()]:1}) + " " + type; + data.push({name, type:"Disease", cells:cellsArray, fill:"url(#hatch12)"}); + }() + + // disaster starting in a random city + void function addDisaster() { + const burg = ra(burgs.filter(b => b.i && !b.removed)); // random burg + if (!burg) return; + + const cellsArray = [], cost = [], power = rand(10, 30); + const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p}); + queue.queue({e:burg.cell, p:0}); + + while (queue.length) { + const next = queue.dequeue(); + if (cells.burg[next.e] || cells.pop[next.e]) cellsArray.push(next.e); + + cells.c[next.e].forEach(function(e) { + const c = rand(1, 10); + const p = next.p + c; + if (p > power) return; + + if (!cost[e] || p < cost[e]) { + cost[e] = p; + queue.queue({e, p}); + } + }); + } + + // Volcanic Eruption, Fault Line, Avalanche, Tsunami + const type = rw({"Famine":5, "Drought":3, "Dearth":1, "Earthquake":3, "Tornadoes":1, "Wildfires":1, "Flood":3}); + data.push({name:type, type:"Disaster", cells:cellsArray, fill:"url(#hatch5)"}); + }() void function drawZones() { zones.selectAll("g").data(data).enter().append("g") - .attr("id", (d, i) => "zone"+i).attr("data-description", d => d.name).attr("data-cells", d => d.cells.join(",")).attr("fill", d => d.fill) + .attr("id", (d, i) => "zone"+i).attr("data-description", d => d.name).attr("data-type", d => d.type) + .attr("data-cells", d => d.cells.join(",")).attr("fill", d => d.fill) .selectAll("polygon").data(d => d.cells).enter().append("polygon") .attr("points", d => getPackPolygon(d)).attr("id", function(d) {return this.parentNode.id+"_"+d}); }() diff --git a/modules/religions-generator.js b/modules/religions-generator.js index 9abaf8a6..dc705c68 100644 --- a/modules/religions-generator.js +++ b/modules/religions-generator.js @@ -22,7 +22,7 @@ number: ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve"], being: ["God", "Goddess", "Lord", "Lady", "Deity", "Creator", "Maker", "Overlord", "Ruler", "Chief", "Master", "Spirit", "Ancestor", "Father", "Forebear", "Forefather", "Mother", "Brother", "Sister", "Elder", "Numen", "Ancient", "Virgin", "Giver", "Council", "Guardian", "Reaper"], animal: ["Antelope", "Ape", "Badger", "Bear", "Beaver", "Bison", "Boar", "Buffalo", "Cat", "Cobra", "Crane", "Crocodile", "Crow", "Deer", "Dog", "Eagle", "Elk", "Fox", "Goat", "Goose", "Hare", "Hawk", "Heron", "Horse", "Hyena", "Ibis", "Jackal", "Jaguar", "Lark", "Leopard", "Lion", "Mantis", "Marten", "Moose", "Mule", "Narwhal", "Owl", "Panther", "Rat", "Raven", "Rook", "Scorpion", "Shark", "Sheep", "Snake", "Spider", "Swan", "Tiger", "Turtle", "Viper", "Vulture", "Walrus", "Wolf", "Wolverine", "Worm", "Camel", "Falcon", "Hound", "Ox", "Serpent"], - adjective: ["New", "Good", "High", "Old", "Great", "Big", "Young", "Major", "Strong", "Happy", "Last", "Main", "Huge", "Far", "Beautiful", "Wild", "Fair", "Prime", "Crazy", "Ancient", "Golden", "Proud", "Secret", "Lucky", "Sad", "Silent", "Latter", "Severe", "Fat", "Holy", "Pure", "Aggressive", "Honest", "Giant", "Mad", "Pregnant", "Distant", "Lost", "Broken", "Blind", "Friendly", "Unknown", "Sleeping", "Slumbering", "Loud", "Hungry", "Wise", "Worried", "Sacred", "Magical", "Superior", "Patient", "Dead", "Deadly", "Peaceful", "Grateful", "Frozen", "Evil", "Scary", "Burning", "Divine", "Bloody", "Dying", "Waking", "Brutal", "Unhappy", "Calm", "Cruel", "Favorable", "Blond", "Explicit", "Disturbing", "Devastating", "Brave", "Sunny", "Troubled", "Flying", "Sustainable", "Marine", "Fatal", "Inherent", "Selected", "Naval", "Cheerful", "Almighty", "Benevolent", "Eternal", "Immutable", "Infallible"], + adjective: ["New", "Good", "High", "Old", "Great", "Big", "Young", "Major", "Strong", "Happy", "Last", "Main", "Huge", "Far", "Beautiful", "Wild", "Fair", "Prime", "Crazy", "Ancient", "Proud", "Secret", "Lucky", "Sad", "Silent", "Latter", "Severe", "Fat", "Holy", "Pure", "Aggressive", "Honest", "Giant", "Mad", "Pregnant", "Distant", "Lost", "Broken", "Blind", "Friendly", "Unknown", "Sleeping", "Slumbering", "Loud", "Hungry", "Wise", "Worried", "Sacred", "Magical", "Superior", "Patient", "Dead", "Deadly", "Peaceful", "Grateful", "Frozen", "Evil", "Scary", "Burning", "Divine", "Bloody", "Dying", "Waking", "Brutal", "Unhappy", "Calm", "Cruel", "Favorable", "Blond", "Explicit", "Disturbing", "Devastating", "Brave", "Sunny", "Troubled", "Flying", "Sustainable", "Marine", "Fatal", "Inherent", "Selected", "Naval", "Cheerful", "Almighty", "Benevolent", "Eternal", "Immutable", "Infallible"], genitive: ["Day", "Life", "Death", "Night", "Home", "Fog", "Snow", "Winter", "Summer", "Cold", "Springs", "Gates", "Nature", "Thunder", "Lightning", "War", "Ice", "Frost", "Fire", "Doom", "Fate", "Pain", "Heaven", "Justice", "Light", "Love", "Time", "Victory"], theGenitive: ["World", "Word", "South", "West", "North", "East", "Sun", "Moon", "Peak", "Fall", "Dawn", "Eclipse", "Abyss", "Blood", "Tree", "Earth", "Harvest", "Rainbow", "Sea", "Sky", "Stars", "Storm", "Underworld", "Wild"], color: ["Dark", "Light", "Bright", "Golden", "White", "Black", "Red", "Pink", "Purple", "Blue", "Green", "Yellow", "Amber", "Orange", "Brown", "Grey"] diff --git a/modules/save-and-load.js b/modules/save-and-load.js index 0e983662..ea3b7bb2 100644 --- a/modules/save-and-load.js +++ b/modules/save-and-load.js @@ -776,7 +776,7 @@ function parseLoadedData(data) { // 1.0 adds zones layer zones = viewbox.insert("g", "#borders").attr("id", "zones").attr("display", "none"); zones.attr("opacity", .6).attr("stroke", null).attr("stroke-width", 0).attr("stroke-dasharray", null).attr("stroke-linecap", "butt"); - addZone(); + addZones(); if (!markers.selectAll("*").size()) {addMarkers(); turnButtonOn("toggleMarkers");} // 1.0 add fogging layer (state focus) diff --git a/modules/ui/heightmap-editor.js b/modules/ui/heightmap-editor.js index 8cee6258..7f5b34ef 100644 --- a/modules/ui/heightmap-editor.js +++ b/modules/ui/heightmap-editor.js @@ -174,7 +174,7 @@ function getHeight(h) { drawStates(); drawBorders(); BurgsAndStates.drawStateLabels(); - addZone(); + addZones(); addMarkers(); console.timeEnd("regenerateErasedData"); console.groupEnd("Edit Heightmap"); diff --git a/modules/ui/tools.js b/modules/ui/tools.js index 4b8ffedd..a4256988 100644 --- a/modules/ui/tools.js +++ b/modules/ui/tools.js @@ -249,6 +249,7 @@ function addLabelOnClick() { const x = width / -2; // x offset; example.remove(); + group.classed("hidden", false); group.append("text").attr("id", id) .append("textPath").attr("xlink:href", "#textPath_"+id).attr("startOffset", "50%").attr("font-size", "100%") .append("tspan").attr("x", x).text(name);